Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

web3j multiple transactions per block not possible? #683

Closed
flefevre opened this issue Aug 27, 2018 · 4 comments
Closed

web3j multiple transactions per block not possible? #683

flefevre opened this issue Aug 27, 2018 · 4 comments

Comments

@flefevre
Copy link
Contributor

flefevre commented Aug 27, 2018

I have tried to create multiple transactions per block but I am not able to do it.
Let's say I have a contract BCThing with 2 attributes (name and collectorContract).
If I can it once, it works
If I made a loop over 5, it populates in the blockchain only the first one...

Do you have any idea where is my typo or misunderstanding of web3j?
I wanted to create this on stackoverflow but there is no web3j tag.

Admin adminWeb3j = SmartContractUtil.getInstance().getAdminWeb3j();
		Credentials credentials = SmartContractUtil.getInstance().getCredentials();
		BigInteger gasPrice = SmartContractUtil.getInstance().GAS_PRICE;
		BigInteger gasLimit = SmartContractUtil.getInstance().GAS_LIMIT;
		List<Long> thingIds = new ArrayList<Long>();
		for(int i=0; i<3;i++) {
			byte[] _name = SmartContractUtil.getInstance().stringToByte("tot"+((new Date()).getTime()));
			String _COLLECTOR_CONTRACT = "0x3baeb8019a9cc9c488aa9355dc522e023a3b406d";
			CompletableFuture<BCThing> trCommand_future =  BCThing.deploy(adminWeb3j, credentials, gasPrice, gasLimit, _name, _COLLECTOR_CONTRACT).sendAsync();
			trCommand_future.thenAccept(trCommand -> {
				try {
					System.out.println("trCommand.getContractAddress="+((BCThing)trCommand_future.get()).name()+"\t"+trCommand.getContractAddress()+"\t"+((BCThing)trCommand_future.get()).COLLECTOR_CONTRACT().send());
				} catch (InterruptedException | ExecutionException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			});
		}

Thanks for your help.

@flefevre
Copy link
Contributor Author

To help, I have switch to the example defined in web3j test, the one with SimpleStorage.
I am trying to deploy it manually 3 times: one with send, then with sendAsync and then sendAsync.
The first one works perfectly
The secund one also
But I never get the last one...

I hope it will help the team to tell me where is the mistake.

TRACE

1535381054639 0Deploy first time with send:
1535381069679 A:0x9f3821955fe7a3aa4454748f11825ee3364677de
1535381069679 Deploy secund time with sendAsync
1535381069682 Deploy third time with sendAsync
1535381069684 Waiting
1535381084708 B:0xe5219f881272657f78c3b011ad9bf6a421204a3c
1535381069684 End

CODE

Date start = new Date();
		SimpleStorage x=null;
		try {
			System.out.println(start.getTime()+"\tDeploy first time with send: ");
			x = SimpleStorage.deploy(web3, credentials2, gasPrice, gasLimit).send();
		} catch (Exception e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		Date done = new Date();
		System.out.println(done.getTime()+"\tA:"+x.getContractAddress());
		
		System.out.println(done.getTime()+"\tDeploy secund time with sendAsync");
		CompletableFuture<SimpleStorage> b = SimpleStorage.deploy(web3, credentials2, gasPrice, gasLimit).sendAsync();
		b.thenAccept(trCommand -> {
			try {
				Date doneB = new Date();
				System.out.println(doneB.getTime()+"\tB:"+b.get().getContractAddress());
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (ExecutionException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		});
		Date done3 = new Date();
		System.out.println(done3.getTime()+"\tDeploy third time with sendAsync");
		CompletableFuture<SimpleStorage> c = SimpleStorage.deploy(web3, credentials2, gasPrice, gasLimit).sendAsync();
		c.thenAccept(trCommand -> {
			try {
				Date doneC = new Date();
				System.out.println(doneC.getTime()+"\tC:"+c.get().getContractAddress());
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (ExecutionException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		});
		Date done4 = new Date();
		System.out.println(done4.getTime()+"\tWaiting");
		try {
			TimeUnit.SECONDS.sleep(120);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		Date done5 = new Date();
		System.out.println(done4.getTime()+"\tEnd");

@flefevre
Copy link
Contributor Author

Dear all,
I have created a small github project with a minimal configuration 1 with the web3j SampleStorage solidity smart contract.
By launching it, you will be able to view:

-my difficulty perhaps to give the right parameters for a private ethereum netrwork

but also a difficulty to use multiple transaction with several instances of the same smart contract.

'''
java.util.concurrent.ExecutionException: java.lang.RuntimeException: java.lang.RuntimeException: Error processing transaction request: replacement transaction underpriced
ending at java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:357)
at java.util.concurrent.CompletableFuture.get(CompletableFuture.java:1895)
'''

  • and also a potential bug with FastRawTransactionManager
    '''
    fastRawTxMgr.getCurrentNonce()=-1
    java.lang.RuntimeException: java.lang.NoSuchMethodException: org.github.web3j.web3jmultipletxsmartcontract.SimpleStorage.(java.lang.String, org.web3j.protocol.Web3j, org.web3j.tx.TransactionManager, org.web3j.tx.gas.ContractGasProvider)
    at org.web3j.tx.Contract.deploy(Contract.java:375)
    at org.web3j.tx.Contract.lambda$deployRemoteCall$6(Contract.java:404)
    at org.web3j.protocol.core.RemoteCall.send(RemoteCall.java:30)
    at org.github.web3j.web3jmultipletxsmartcontract.MultipleCreationFastTransactionManager.main(MultipleCreationFastTransactionManager.java:61)
    Caused by: java.lang.NoSuchMethodException: org.github.web3j.web3jmultipletxsmartcontract.SimpleStorage.(java.lang.String, org.web3j.protocol.Web3j, org.web3j.tx.TransactionManager, org.web3j.tx.gas.ContractGasProvider)
    at java.lang.Class.getConstructor0(Class.java:3082)
    at java.lang.Class.getDeclaredConstructor(Class.java:2178)
    at org.web3j.tx.Contract.deploy(Contract.java:362)
    ... 3 more
    Contract is null
    '''

I hope this will help you.

@flefevre
Copy link
Contributor Author

The github repository:
'''
git clone https://github.com/flefevre/web3jmultipletx
cd web3jmultipletx
mvn clean install -f web3jmultipletxsmartcontract/pom.xml
'''

look at the readme

@flefevre
Copy link
Contributor Author

We Can close this sincère i have described it more clearly here

FastRawTransactionManager is not able to deploy smartcontract #688

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant