xuperchain / xuper-java-sdk

The java sdk of xuperunion https://github.com/xuperchain/xuperunion
Apache License 2.0
27 stars 22 forks source link

Err:500-50400-verify tx failed+err:V__交易哈希验证不匹配 #43

Open LKCoinOne opened 2 years ago

LKCoinOne commented 2 years ago

执行代码:

1、创建平行链 g-test01 为noFee = true的时候,会产生下面的异常;

2、创建平行链 g-test02 为noFee = false的时候,异常消失;

推测原因:java-sdk 对平行链:noFee = true ,无通证模式,支持不友好;(go-sdk)没有该问题

public class Counter {
    private Account account;
    private XuperClient client;
    private final Gson gson = new Gson();

    private final static String ip = "192.168.3.101";
    private final static String port = "37102";
    private final static String CONTRACT_NAME = "counter01";

    @Before
    public void setUp() {
        try {
            client = new XuperClient(ip + ":" + port);
            client.setChainName("g-test01");
            account = Account.retrieve("move thumb educate trophy grass crystal gossip appear ability they theory cage",2);
        } catch (Exception e) {
            assumeNoException(e);
        }
    }

    @After
    public void tearDown() {
        client.close();
    }

    @Test
    public void createContractAccount() throws Exception {

        Transaction tx = client.createContractAccount(account, "XC7759084454738511@g-fee-1114");

        System.out.println("create account " + tx.getTxid());
        // waiting create account tx confirmed
        sleep(4000);
    }

    @Test
    public void deployWasmContract() throws Exception {
        account.setContractAccount("XC7376100300412583@g-fee-1114");//4303197f5894727efdff2858113d44a7c57865674628060c67af4230c9d64dfd
        Map<String, byte[]> args = new HashMap<>();
        args.put("creator", "XC7376100300412583@g-fee-1114".getBytes());
        String codePath = "E:\\guohongsen\\mycode\\xuper-java-sdk\\src\\test\\resources\\com\\baidu\\xuper\\api\\" + CONTRACT_NAME + ".wasm";
        byte[] code = Files.readAllBytes(Paths.get(codePath));
        Transaction tx = client.deployWasmContract(account, code, CONTRACT_NAME, "c", args);
        printTx(tx);
    }

    @Test
    public void increase() throws Exception {
        Map<String, byte[]> args = new HashMap<>();
        args.put("key", "1111".getBytes());

        Transaction tx = client.invokeContract(account, "wasm", CONTRACT_NAME, "increase", args);
        printTx(tx);
    }

    @Test
    public void get() throws Exception {
        Map<String, byte[]> args = new HashMap<>();
        args.put("key", "中奖次数".getBytes());

        Transaction tx = client.invokeContract(account, "wasm", CONTRACT_NAME, "get", args);
        printTx(tx);
    }

    public void  printTx(Transaction tx) {
        ContractResponse contractResponse = tx.getContractResponse();
        String hash = tx.getTxid();
        long fee = tx.getGasUsed();

        System.out.println("合约返回状态:" + contractResponse.getStatus());
        System.out.println("合约返回消息:" + contractResponse.getMessage());
        System.out.println("合约返回内容:" + contractResponse.getBodyStr());
        System.out.println("燃料消耗:" + fee);
        System.out.println("hash:" + hash);
        System.out.println(gson.toJson(tx.getRawTx()));
    }
}

报错问题:

io.grpc.StatusRuntimeException: UNKNOWN: Err:500-50400-verify tx failed+err:V__交易哈希验证不匹配

    at io.grpc.stub.ClientCalls.toStatusRuntimeException(ClientCalls.java:240)
    at io.grpc.stub.ClientCalls.getUnchecked(ClientCalls.java:221)
    at io.grpc.stub.ClientCalls.blockingUnaryCall(ClientCalls.java:140)
    at com.baidu.xuper.pb.XchainGrpc$XchainBlockingStub.postTx(XchainGrpc.java:1622)
    at com.baidu.xuper.api.Transaction.send(Transaction.java:487)
    at com.baidu.xuper.api.XuperClient.invokeContract(XuperClient.java:114)
    at com.baidu.xuper.api.Counter.increase(Counter.java:76)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
    at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
    at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
    at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
    at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
    at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
    at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)
superlitian commented 2 years ago

链接到 noFee 的平行链之后,每一笔交易都验证失败吗?