hyperledger-archives / iroha

Iroha - A simple, decentralized ledger

Home Page:http://iroha.tech

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CreateAccount permission issue

big-fish0 opened this issue · comments

this is my code:

package com.iroha.test;

import java.io.File;
import java.io.IOException;
import java.math.BigInteger;
import java.nio.file.Files;
import java.nio.file.Paths;

import com.bjb.service.IrohaTransaction;
import com.bjb.util.Constant;
import com.google.protobuf.InvalidProtocolBufferException;

import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import iroha.protocol.BlockOuterClass;
import iroha.protocol.CommandServiceGrpc;
import jp.co.soramitsu.iroha.ByteVector;
import jp.co.soramitsu.iroha.Keypair;
import jp.co.soramitsu.iroha.ModelCrypto;
import jp.co.soramitsu.iroha.ModelProtoTransaction;
import jp.co.soramitsu.iroha.ModelTransactionBuilder;
import jp.co.soramitsu.iroha.PrivateKey;
import jp.co.soramitsu.iroha.PublicKey;
import jp.co.soramitsu.iroha.UnsignedTx;

public class Test {

	static {
        try {
        	System.loadLibrary("ed25519");
        	System.loadLibrary("protobuf");
            System.loadLibrary("irohajava");
        } catch (UnsatisfiedLinkError e) {
            System.err.println("Native code library failed to load. \n" + e);
            System.exit(1);
        }
    }
	
	public static void main(String[] args) {
		for (int i = 0; i < 10; i++) {
			irohaThread it = new irohaThread();
			it.start();
		}

	}

}


class irohaThread extends Thread{
	
	static long preTime = 0;
	static int count = 100;
	private static ModelCrypto crypto = new ModelCrypto();
	private static ModelTransactionBuilder txBuilder = new ModelTransactionBuilder();
	  
	public static byte[] toByteArray(ByteVector blob)
	{
	    byte[] bs = new byte[(int)blob.size()];
	    for (int i = 0; i < blob.size(); i++) {
	    	bs[i] = ((byte)blob.get(i));
	    }
	    return bs;
	}
	  
	public static String readKeyFromFile(String path)
	{
	    try
	    {
	    	return new String(Files.readAllBytes(Paths.get(path, new String[0])));
	    }
	    catch (IOException e)
	    {
	    	System.err.println("Unable to read key files.\n " + e);
	    	System.exit(1);
	    }
	    return "";
	}	
	
	Keypair keys = crypto.convertFromExisting(readKeyFromFile("./admin@test.pub"),readKeyFromFile("./admin@test.priv"));
    String creator = "admin@test";
    
	
	@Override
	public void run() {
		for (int i = 0; i < 10; i++) {
			count+=1;
			long currentTime = System.currentTimeMillis();
			System.out.println(currentTime);
		   
			Keypair keypair = crypto.generateKeypair();
			PublicKey pubkey = keypair.publicKey();
		    UnsignedTx utx = txBuilder.creatorAccountId(creator).createdTime(BigInteger.valueOf(currentTime)).createAccount("mytest"+count, "test", pubkey).build();

		    
		    ByteVector txblob = new ModelProtoTransaction(utx).signAndAddSignature(keys).finish().blob();
		    
		
		    byte[] bs = toByteArray(txblob);
		    
		
		    BlockOuterClass.Transaction protoTx = null;
		    try
		    {
		      protoTx = BlockOuterClass.Transaction.parseFrom(bs);
		    }
		    catch (InvalidProtocolBufferException e)
		    {
		      System.err.println("Exception while converting byte array to protobuf:" + e.getMessage());
		      System.exit(1);
		    }
		    ManagedChannel channel = ManagedChannelBuilder.forAddress("192.168.1.211", 50051).usePlaintext(true).build();
		    CommandServiceGrpc.CommandServiceBlockingStub stub = CommandServiceGrpc.newBlockingStub(channel);
		    stub.torii(protoTx);
		    
		 //   System.out.println("done");
	    }
	}
}

and this is the part of the logs:

2018-07-06 08:10:38.929741101][th:29][error] PostgresWsvQuery ERROR:  current transaction is aborted, commands ignored until end of transaction block

[2018-07-06 08:10:38.932572499][th:29][error] PostgresWsvQuery ERROR:  current transaction is aborted, commands ignored until end of transaction block

[2018-07-06 08:10:38.935839931][th:29][error] PostgresWsvQuery ERROR:  current transaction is aborted, commands ignored until end of transaction block

[2018-07-06 08:10:38.938819358][th:29][error] PostgresWsvQuery ERROR:  current transaction is aborted, commands ignored until end of transaction block

[2018-07-06 08:10:38.946073312][th:29][error] PostgresWsvQuery ERROR:  current transaction is aborted, commands ignored until end of transaction block

[2018-07-06 08:10:38.949262446][th:29][error] PostgresWsvQuery ERROR:  current transaction is aborted, commands ignored until end of transaction block

[2018-07-06 08:10:38.949693352][th:70][info] TxProcessor handle transaction
[2018-07-06 08:10:38.949780143][th:70][info] TxProcessor propagating tx
[2018-07-06 08:10:38.949819811][th:70][info] PCS propagate tx
[2018-07-06 08:10:38.949853250][th:70][info] OrderingGate propagate tx, account_id:  account_id: admin@test
[2018-07-06 08:10:38.949887878][th:70][info] OrderingGate Propagate tx (on transport)
[2018-07-06 08:10:38.950282033][th:56][info] OrderingServiceTransportGrpc OrderingServiceTransportGrpc::onTransaction
[2018-07-06 08:10:38.950368935][th:56][info] OrderingServiceImpl Queue size is 4
[2018-07-06 08:10:38.952206365][th:70][info] TxProcessor handle transaction
[2018-07-06 08:10:38.952344539][th:70][info] TxProcessor propagating tx
[2018-07-06 08:10:38.952388170][th:70][info] PCS propagate tx
[2018-07-06 08:10:38.952451926][th:70][info] OrderingGate propagate tx, account_id:  account_id: admin@test
[2018-07-06 08:10:38.952487190][th:70][info] OrderingGate Propagate tx (on transport)
[2018-07-06 08:10:38.952782022][th:69][info] TxProcessor handle transaction
[2018-07-06 08:10:38.952856623][th:56][info] OrderingServiceTransportGrpc OrderingServiceTransportGrpc::onTransaction
[2018-07-06 08:10:38.952884927][th:69][info] TxProcessor propagating tx
[2018-07-06 08:10:38.952923607][th:69][info] PCS propagate tx
[2018-07-06 08:10:38.952922699][th:56][info] OrderingServiceImpl Queue size is 5
[2018-07-06 08:10:38.952977531][th:69][info] OrderingGate propagate tx, account_id:  account_id: admin@test
[2018-07-06 08:10:38.953250475][th:69][info] OrderingGate Propagate tx (on transport)
[2018-07-06 08:10:38.953743635][th:56][info] OrderingServiceTransportGrpc OrderingServiceTransportGrpc::onTransaction
[2018-07-06 08:10:38.953809807][th:56][info] OrderingServiceImpl Queue size is 6
[2018-07-06 08:10:38.957271875][th:70][info] TxProcessor handle transaction
[2018-07-06 08:10:38.957359682][th:70][info] TxProcessor propagating tx
[2018-07-06 08:10:38.957402473][th:70][info] PCS propagate tx
[2018-07-06 08:10:38.957436155][th:70][info] OrderingGate propagate tx, account_id:  account_id: admin@test
[2018-07-06 08:10:38.957470890][th:70][info] OrderingGate Propagate tx (on transport)
[2018-07-06 08:10:38.957845657][th:71][info] OrderingServiceTransportGrpc OrderingServiceTransportGrpc::onTransaction
[2018-07-06 08:10:38.957916150][th:71][info] OrderingServiceImpl Queue size is 7
[2018-07-06 08:10:38.958662913][th:29][info] SFV transactions in verified proposal: 4
[2018-07-06 08:10:38.958796849][th:29][info] Simulator process verified proposal
[2018-07-06 08:10:38.960365528][th:29][info] YacGate vote for block (59626661556ef80f8108a08de73b4101b37b87763048cbe42cc5a6b60091b8d3, Hash: [59626661556ef80f8108a08de73b4101b37b87763048cbe42cc5a6b60091b8d3 ])
[2018-07-06 08:10:38.961047761][th:29][info] YAC Order for voting: {localhost:10001}
[2018-07-06 08:10:38.961538753][th:29][info] YAC Vote for hash (59626661556ef80f8108a08de73b4101b37b87763048cbe42cc5a6b60091b8d3, 59626661556ef80f8108a08de73b4101b37b87763048cbe42cc5a6b60091b8d3)
[2018-07-06 08:10:38.961837398][th:29][info] YacNetwork Send vote 59626661556ef80f8108a08de73b4101b37b87763048cbe42cc5a6b60091b8d3 to localhost:10001
[2018-07-06 08:10:38.961907896][th:29][error] Simulator stateful validation error: could not validate command with index 0: CreateAccount: has permission command validation failed: account admin@test does not have permission can_create_account
[2018-07-06 08:10:38.961945363][th:29][error] Simulator stateful validation error: could not validate command with index 0: CreateAccount: has permission command validation failed: account admin@test does not have permission can_create_account
[2018-07-06 08:10:38.961979045][th:29][error] Simulator stateful validation error: could not validate command with index 0: CreateAccount: has permission command validation failed: account admin@test does not have permission can_create_account
[2018-07-06 08:10:38.962009573][th:29][error] Simulator stateful validation error: could not validate command with index 0: CreateAccount: has permission command validation failed: account admin@test does not have permission can_create_account
[2018-07-06 08:10:38.962041403][th:71][info] YacNetwork Receive vote 59626661556ef80f8108a08de73b4101b37b87763048cbe42cc5a6b60091b8d3 from ipv4:127.0.0.1:49784
[2018-07-06 08:10:38.962113608][th:29][error] Simulator stateful validation error: could not validate command with index 0: CreateAccount: has permission command validation failed: account admin@test does not have permission can_create_account
[2018-07-06 08:10:38.962149882][th:29][error] Simulator stateful validation error: could not validate command with index 0: CreateAccount: has permission command validation failed: account admin@test does not have permission can_create_account

@big-fish0, please send us your genesis block and config

@big-fish0, which version of Iroha do you use?

@Alexey-N-Chernyshov
I got the iroha source and image at 2018-07-03

genesis.block

{
   "payload":{
      "transactions":[
         {
            "payload":{
               "commands":[
                  {
                     "addPeer":{
                        "peer":{
                           "address":"localhost:10001",
                           "peerKey":"0E2icbV/5jQmrh3Jf2lSEEA3QR/PTztzncIX9F5fyZs="
                        }
                     }
                  },
                  {
                     "createRole":{
                        "roleName":"admin",
                        "permissions":[
                           "can_add_peer",
                           "can_add_signatory",
                           "can_create_account",
                           "can_create_domain",
                           "can_get_all_acc_ast",
                           "can_get_all_acc_ast_txs",
                           "can_get_all_acc_detail",
                           "can_get_all_acc_txs",
                           "can_get_all_accounts",
                           "can_get_all_signatories",
                           "can_get_all_txs",
                           "can_get_roles",
                           "can_read_assets",
                           "can_remove_signatory",
                           "can_set_quorum",
                           "can_get_blocks",
                           "can_subtract_asset_qty"
                        ]
                     }
                  },
                  {
                     "createRole":{
                        "roleName":"user",
                        "permissions":[
                           "can_add_signatory",
                           "can_get_my_acc_ast",
                           "can_get_my_acc_ast_txs",
                           "can_get_my_acc_detail",
                           "can_get_my_acc_txs",
                           "can_get_my_account",
                           "can_get_my_signatories",
                           "can_get_my_txs",
                           "can_grant_can_add_my_signatory",
                           "can_grant_can_remove_my_signatory",
                           "can_grant_can_set_my_account_detail",
                           "can_grant_can_set_my_quorum",
                           "can_grant_can_transfer_my_assets",
                           "can_receive",
                           "can_remove_signatory",
                           "can_set_quorum",
                           "can_transfer",
                           "can_add_asset_qty",
                           "can_create_asset",
                           "can_subtract_asset_qty"
                        ]
                     }
                  },
                  {
                     "createRole":{
                        "roleName":"money_creator",
                        "permissions":[
                           "can_add_asset_qty",
                           "can_create_asset",
                           "can_receive",
                           "can_transfer"
                        ]
                     }
                  },
                  {
                     "createDomain":{
                        "domainId":"test",
                        "defaultRole":"user"
                     }
                  },
		  {
                     "createDomain":{
                        "domainId":"sun",
                        "defaultRole":"user"
                     }
                  },

                  {
                     "createDomain":{
                        "domainId":"sun-0555",
                        "defaultRole":"user"
                     }
                  },

                  {
                     "createAsset":{
                        "assetName":"point",
                        "domainId":"sun",
                        "precision":0
                     }
                  },
                  {
                     "createAccount":{
                        "accountName":"admin",
                        "domainId":"test",
                        "mainPubkey":"iJ9riB4zG+IUh9t33PMsX409XoBm540v6sQjn+kdQW8="
                     }
                  },
                  {
                     "createAccount":{
                        "accountName":"test",
                        "domainId":"test",
                        "mainPubkey":"3MfszkSPLhkKSBrsfKIe5S7aVG5mC0gg9JdtATIVcJc="
                     }
                  },
                  {
                     "appendRole":{
                        "accountId":"admin@test",
                        "roleName":"admin"
                     }
                  },
                  {
                     "appendRole":{
                        "accountId":"admin@test",
                        "roleName":"money_creator"
                     }
                  }
               ]
            }
         }
      ],
      "txNumber":1,
      "height":"1",
      "prevBlockHash":"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="
   }
}

config.docker

{
  "block_store_path" : "/tmp/block_store/",
  "torii_port" : 50051,
  "internal_port" : 10001,
  "pg_opt" : "host=iroha0_postgres_1 port=5432 user=postgres password=mysecretpassword",
  "max_proposal_size" : 10,
  "proposal_delay" : 5000,
  "vote_delay" : 5000,
  "load_delay" : 5000,
  "mst_enable" : false
}

This time I use the account(admin@test) to create some accounts ,About 95% is successed,but 5% is failed.
The log tells me that CreateAccount: has permission command validation failed: account admin@test does not have permission can_create_account

@big-fish0, could you reproduce the bug on the latest develop? It seems it works well now. And specify commit you have used when encountered a bug, please.

@Alexey-N-Chernyshov
Yes,I use the same code can get the bug everytime. Which day the is latest develop version,mine is 2018-07-03.
I used 10 threads x 10 loop to createAccount,and the account's name like test1@test,test2@test,test3@test ......

@Alexey-N-Chernyshov
You can see my code at 1L,maybe the error is the static parameter count,Maybe it is my code occurs this bug

commented

Seems outdated