使用 Web3j 超時進行仲裁部署
設想:
我有以下程式碼:
final String hostUrl = this.deployerProperties.getProperty("quorum.host.url"); final String hostPort = this.deployerProperties.getProperty("quorum.host.port"); final String host = hostUrl + ":" + hostPort; final HttpService httpService = new HttpService(host); this.admin = Admin.build(httpService); this.quorum = Quorum.build(httpService); final EthAccounts ethAccounts = this.quorum.ethAccounts().send(); final String ethFirstAccount = ethAccounts.getAccounts().get(0); final PersonalUnlockAccount personalUnlockAccount = this.admin.personalUnlockAccount(ethFirstAccount, "").send(); if (!personalUnlockAccount.accountUnlocked()) { throw new IllegalStateException("Account " + ethFirstAccount + " can not be unlocked!"); } final List<String> privateFor = null; int sleepDuration = 2 * 1000; int attempts =50; final ClientTransactionManager clientTransactionManager = new ClientTransactionManager(this.quorum, ethFirstAccount, ethFirstAccount, privateFor); //final ContractGasProvider contractGasProvider = new DefaultGasProvider(); final ContractGasProvider contractGasProvider = new PersonalGasProvider(); final Tokens tokens = Tokens.deploy(this.quorum, clientTransactionManager, contractGasProvider).send(); public class PersonalGasProvider extends StaticGasProvider { public static final BigInteger GAS_LIMIT = DefaultGasProvider.GAS_LIMIT; public static final BigInteger GAS_PRICE = BigInteger.ZERO; public PersonalGasProvider() { super(GAS_PRICE, GAS_LIMIT); } }
當我執行程式碼時。我收到以下錯誤:
0xbb0792515b9b84bb6d41956925027db0d8b4636470c475987b882993a257f974在org.web3j.tx.response.PollingTransactionReceiptProcessor.getTransactionReceipt(PollingTransactionReceiptProcessor.java:51)在組織:100秒交易後不產生交易收據:異常線上程“主”org.web3j.protocol.exceptions.TransactionException。 web3j.tx.response.PollingTransactionReceiptProcessor.waitForTransactionReceipt(PollingTransactionReceiptProcessor.java:29) 在 org.web3j.tx.TransactionManager.processResponse(TransactionManager.java:72) 在 org.web3j.tx.TransactionManager.executeTransaction(TransactionManager.java:51)在 org.web3j.tx.ManagedTransaction.send(ManagedTransaction.java:87) 在 org.web3j.tx.Contract.executeTransaction(Contract.java:291) 在 org.web3j.tx.Contract.create(Contract.java:333) 在 org.web3j.tx.Contract.deploy(Contract.java:387) 在 org.web3j.tx.Contract.lambda $ deployRemoteCall $ 10(Contract.java:496)在 org.web3j.protocol.core.RemoteCall.send(RemoteCall.java:30)
此 java 程式碼隨機執行,因為 10% 的執行程式碼成功完成了執行。但是其他 90% 的執行都出現了錯誤。
流程如下:
- Quorum 7nodes 範例部署到遠端伺服器
- 打包到 JAR 中的智能合約包裝器
- 一個簡單的程式碼執行包裝器部署方法
知道發生了什麼嗎?
編輯
有了這個錯誤,錯誤仍然存在,IDE 警告我部署建構子已被棄用
final ClientTransactionManager clientTransactionManager = new ClientTransactionManager(this.quorum, ethFirstAccount, /* ethFirstAccount */null, privateFor, attempts, sleepDuration); final Users users = Users.deploy(this.quorum, clientTransactionManager, BigInteger.valueOf(0), BigInteger.valueOf(30000000) /* contractGasProvider */).send();
在事務被卡在待處理隊列上之前,我已經看到過這個問題(在舊版本的仲裁上,存在可能導致事務被卡住的缺陷)。我建議您檢查事務是否命中 geth 節點,以及它是否卡在待處理隊列中。如果您有舊的仲裁版本,請嘗試 v2.2.3。
我沒有 Token 合約程式碼,但我用 SimpleContract 嘗試了你的程式碼,它對我來說很好,除了我必須使用自己的 GasProvider 來編譯它:
public class DeployGasProvider extends StaticGasProvider{ public DeployGasProvider() { super(GAS_PRICE, GAS_LIMIT); } }
這是我正在使用的程式碼:
ClientTransactionManager clientTransactionManager = new ClientTransactionManager(this.quorum, ethFirstAccount, ethFirstAccount, privateFor); ContractGasProvider contractGasProvider = new DeployGasProvider(); SimpleStorage tokens = SimpleStorage.deploy(this.quorum, clientTransactionManager, contractGasProvider).send();