aionnetwork / AVM

Enabling Java code to run in a blockchain environment
https://theoan.com/
MIT License
49 stars 25 forks source link

[CLOSED] Update Bloom filters for avm transactions #318

Closed aionbot closed 5 years ago

aionbot commented 5 years ago

Issue created by aionick (on Monday Nov 26, 2018 at 15:32 GMT)

Currently the bloom filter corresponding to an Avm transaction is a zero byte array and represents nothing. This needs to be fixed so that the filter actually is updated correctly. This should also allow us to be able to search logs by topic once this is working.

aionbot commented 5 years ago

Comment by jeff-aion (on Tuesday Dec 04, 2018 at 14:55 GMT)

What is the current state of this? I remember some work being done, related to this, but is it finished or is something still being done?

aionbot commented 5 years ago

Comment by nancyaion (on Tuesday Dec 04, 2018 at 15:57 GMT)

Validated via "LogTest" that the bloom filter already works for AVM transactions. It records the address and the topic if there is a log. Bloom is 256 bytes. In this test, only 6 bytes are changed to non-zeros, so we didn't notice earlier that it is not zero anymore.

aionbot commented 5 years ago

Comment by nancyaion (on Tuesday Dec 04, 2018 at 16:01 GMT)

Also confirmed with Beta build, in the console log,

18-12-04 11:00:24.023 DEBUG VM [pow]: Transaction receipt: TransactionReceipt[ , postTxState= , error= , executionResult= , bloom=00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000008000002000000000000000000000000000000000000000000200000000000000000040000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 , logs=[LogInfo{address=0x0fc118c6b6db8d4a8a5f3442445cab5a39b91f733bf0bd214657f6a865a3d9fb, topics=[486974436f756e746572 ], data=31}] , nrgUsed=66891]

aionbot commented 5 years ago

Comment by nancyaion (on Tuesday Dec 04, 2018 at 18:35 GMT)

This is the log added to the HardcodedBetaTransactionsTarget, BlockchainRuntime.log("HitCounter".getBytes(), String.valueOf(counter).getBytes());

Validation via beta.sh

nancy@adlnancy:~/repos/integration_kernel$ ./beta.sh --get-all-logs -a 0f9a9c39a8c7564523f69ff88fc1093d91a59576d67457e3dd650ac05dcd7066

The logs matching the specified filter are: {"result":[{"blockHash":"0x643fff7288911b65d55da143c2d2f542153ca54ea5ab360de5aee53ad3134498","logIndex":"0x0","address":"0x0f9a9c39a8c7564523f69ff88fc1093d91a59576d67457e3dd650ac05dcd7066","removed":false,"data":"0x31","topics":["0x486974436f756e746572"],"blockNumber":"0x2f","transactionIndex":"0x0","transactionHash":"0x3a7c1bef68305cc40ac168ff53f8ee355c57e6b2ef13c421a871f7adb0283e93"}],"id":null,"jsonrpc":"2.0"}

nancy@adlnancy:~/repos/integration_kernel$ ./beta.sh --get-receipt 0x3a7c1bef68305cc40ac168ff53f8ee355c57e6b2ef13c421a871f7adb0283e93 Your transaction receipt is:

{"blockHash":"0x643fff7288911b65d55da143c2d2f542153ca54ea5ab360de5aee53ad3134498","nrgPrice":"0x01","logsBloom":"00000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000080000000008000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000","nrgUsed":"0x01054b","contractAddress":null,"transactionIndex":"0x0","transactionHash":"0x3a7c1bef68305cc40ac168ff53f8ee355c57e6b2ef13c421a871f7adb0283e93","gasLimit":"0x1e8480","cumulativeNrgUsed":"0x1054b","gasUsed":"0x01054b","blockNumber":"0x2f","root":"ce67a158de10dc397c5cb211c0a9cc81851ee1e90aaaf1e4ac3acbb37f264ce2","cumulativeGasUsed":"0x1054b","from":"0xa039fa5cae7f7a9441a480f3de49954f6230d4e33966c34146657556171c5ec4","to":"0x0f9a9c39a8c7564523f69ff88fc1093d91a59576d67457e3dd650ac05dcd7066","logs":[{"address":"0x0f9a9c39a8c7564523f69ff88fc1093d91a59576d67457e3dd650ac05dcd7066","logIndex":"0x0","data":"0x31","topics":["0x486974436f756e746572"],"blockNumber":"0x2f","transactionIndex":"0x0"}],"gasPrice":"0x01","status":"0x1"}

Bloom value validated by this program,

@Test public void testBloom() { Bloom targetBloom = BloomFilter.create("HitCounter".getBytes()); targetBloom.or(BloomFilter.create(hexStringToByteArray("0f9a9c39a8c7564523f69ff88fc1093d91a59576d67457e3dd650ac05dcd7066"))); Bloom actualBloom = new Bloom(hexStringToByteArray("00000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000080000000008000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000")); assertTrue(actualBloom.matches(targetBloom)); }

public static byte[] hexStringToByteArray(String s) {
    int len = s.length();
    byte[] data = new byte[len / 2];
    for (int i = 0; i < len; i += 2) {
        data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4)
                + Character.digit(s.charAt(i+1), 16));
    }
    return data;
}
aionbot commented 5 years ago

Comment by nancyaion (on Tuesday Dec 04, 2018 at 22:13 GMT)

Confirmed that the query-by-topic issue is not relevant to the Bloom filter.

The topics filter in kernel web3 API only works with 32 bytes topic value, thus works for FVM topics as they are hash values of 32 bytes. Our current AVM topics are defined as arbitrary length byte arrays. ./beta.sh --get-all-logs -t option only works when the AVM topic happens to be of 32 bytes length. Fixes will be tracked by issue #325.

Close this one.