-
Notifications
You must be signed in to change notification settings - Fork 954
Bonsai Archive (with state proofs) #8669
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
Conversation
Signed-off-by: Jason Frame <jason.frame@consensys.net>
…se constructor that reuses worldStateStorage so that we don't lose values in the EvmToolSpecTests Signed-off-by: Jason Frame <jason.frame@consensys.net>
Signed-off-by: Jason Frame <jason.frame@consensys.net>
Signed-off-by: Matthew Whitehead <matthew1001@gmail.com>
…d state, and freeze it Signed-off-by: Matthew Whitehead <matthew1001@gmail.com>
Signed-off-by: Matthew Whitehead <matthew1001@gmail.com>
…ten for blocks and move account state to new DB segment Signed-off-by: Matthew Whitehead <matthew1001@gmail.com>
Signed-off-by: Matthew Whitehead <matthew1001@gmail.com>
Signed-off-by: Matthew Whitehead <matthew1001@gmail.com>
…t block state has been frozen for Signed-off-by: Matthew Whitehead <matthew1001@gmail.com>
Signed-off-by: Matthew Whitehead <matthew1001@gmail.com>
Signed-off-by: Matthew Whitehead <matthew1001@gmail.com>
…age from the freezer segment Signed-off-by: Matthew Whitehead <matthew1001@gmail.com>
Signed-off-by: Matthew Whitehead <matthew1001@gmail.com>
Signed-off-by: Matthew Whitehead <matthew1001@gmail.com>
…or DB mode Signed-off-by: Matthew Whitehead <matthew1001@gmail.com>
… time. Add more tests Signed-off-by: Matthew Whitehead <matthew1001@gmail.com>
… a time Signed-off-by: Matthew Whitehead <matthew1001@gmail.com>
Signed-off-by: Matthew Whitehead <matthew1001@gmail.com>
Signed-off-by: Matthew Whitehead <matthew1001@gmail.com>
Signed-off-by: Matthew Whitehead <matthew1001@gmail.com>
Signed-off-by: Matthew Whitehead <matthew1001@gmail.com>
Signed-off-by: Matthew Whitehead <matthew1001@gmail.com>
…Use the term archive, not freezer Signed-off-by: Matthew Whitehead <matthew1001@gmail.com>
Signed-off-by: Matthew Whitehead <matthew1001@gmail.com>
Signed-off-by: Matthew Whitehead <matthew1001@gmail.com>
Signed-off-by: Matthew Whitehead <matthew1001@gmail.com>
…to fail the block Signed-off-by: Matthew Whitehead <matthew1001@gmail.com>
Signed-off-by: Matthew Whitehead <matthew1001@gmail.com>
Signed-off-by: Matthew Whitehead <matthew1001@gmail.com>
Signed-off-by: Matthew Whitehead <matthew1001@gmail.com>
Signed-off-by: Matthew Whitehead <matthew1001@gmail.com>
Signed-off-by: Matthew Whitehead <matthew1001@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few early questions and observations - still getting up to speed on the storage subsystem, so some of these may miss the mark. Also I understand it’s still a WIP, so feel free to disregard anything off-base @matthew1001 . I’ll probably have more feedback as I go through the rest in more detail in effort to fully understand the implementation.
I can also add that, speaking for Absa, we wouldn't oppose merging BONSAI_ARCHIVE
and BONSAI_ARCHIVE_PROOFS
into a single storage format functionally equivalent to the latter. For our use-cases, full auditability and data integrity are non-negotiable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe as part of the data storage config validation we should also assert that the checkpoint interval is positive?
|
||
if (DataStorageFormat.X_BONSAI_ARCHIVE_PROOFS != dataStorageFormat) { | ||
if (unstableOptions.archiveTrieNodeCheckpointInterval | ||
!= DEFAULT_ARCHIVE_CHECKPOINT_INTERVAL) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Obviously this is not ideal as the exception will not be triggered if the checkpoint interval is set to the default value. There are other issues with the CLI arg parsing in general but it can and should be addressed separately.
DataStorageFormat.BONSAI.equals(config.getDataStorageFormat()), | ||
"Subcommand only works with data-storage-format=BONSAI"); | ||
config.getDataStorageFormat().isBonsaiFormat(), | ||
"Subcommand only works with data-storage-format=BONSAI or X_BONSAI_ARCHIVE"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Subcommand only works with data-storage-format=BONSAI or X_BONSAI_ARCHIVE"); | |
"Subcommand only works with data-storage-format=BONSAI or X_BONSAI_ARCHIVE or X_BONSAI_ARCHIVE_PROOFS"); |
: (dataStorageFormat == X_BONSAI_ARCHIVE | ||
? BaseVersionedStorageFormat.BONSAI_ARCHIVE_WITH_RECEIPT_COMPACTION | ||
: BaseVersionedStorageFormat.FOREST_WITH_RECEIPT_COMPACTION); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
: (dataStorageFormat == X_BONSAI_ARCHIVE | |
? BaseVersionedStorageFormat.BONSAI_ARCHIVE_WITH_RECEIPT_COMPACTION | |
: BaseVersionedStorageFormat.FOREST_WITH_RECEIPT_COMPACTION); | |
: dataStorageFormat == X_BONSAI_ARCHIVE | |
? BaseVersionedStorageFormat.BONSAI_ARCHIVE_WITH_RECEIPT_COMPACTION | |
: dataStorageFormat == X_BONSAI_ARCHIVE_PROOFS | |
? BaseVersionedStorageFormat.BONSAI_ARCHIVE_PROOFS_WITH_RECEIPT_COMPACTION | |
: BaseVersionedStorageFormat.FOREST_WITH_RECEIPT_COMPACTION; |
: (dataStorageFormat == X_BONSAI_ARCHIVE | ||
? BaseVersionedStorageFormat.BONSAI_ARCHIVE_WITH_RECEIPT_COMPACTION | ||
: BaseVersionedStorageFormat.FOREST_WITH_RECEIPT_COMPACTION); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
: (dataStorageFormat == X_BONSAI_ARCHIVE | |
? BaseVersionedStorageFormat.BONSAI_ARCHIVE_WITH_RECEIPT_COMPACTION | |
: BaseVersionedStorageFormat.FOREST_WITH_RECEIPT_COMPACTION); | |
: dataStorageFormat == X_BONSAI_ARCHIVE | |
? BaseVersionedStorageFormat.BONSAI_ARCHIVE_WITH_RECEIPT_COMPACTION | |
: dataStorageFormat == X_BONSAI_ARCHIVE_PROOFS | |
? BaseVersionedStorageFormat.BONSAI_ARCHIVE_PROOFS_WITH_RECEIPT_COMPACTION | |
: BaseVersionedStorageFormat.FOREST_WITH_RECEIPT_COMPACTION; |
* The FlatDbMode enum represents the different modes of the flat database. It has two modes: | ||
* PARTIAL and FULL. | ||
* The FlatDbMode enum represents the different modes of the flat database. It has three modes: | ||
* PARTIAL, FULL, and ARCHIVE. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem to be the case, as both archive storage mode variants have their own partial and full flat db strategy?
executeAsync.accept( | ||
() -> { | ||
if (archiveMutex.tryLock()) { | ||
try { | ||
moveBlockStateToArchive(); | ||
} finally { | ||
archiveMutex.unlock(); | ||
} | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might it be more efficient to run a batch job every couple of blocks to avoid the overhead of starting tasks just to find that the lock is taken?
try { | ||
moveBlockStateToArchive(); | ||
} finally { | ||
archiveMutex.unlock(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be useful to log any exceptions thrown from moveBlockStateToArchive
.
.forEach( | ||
(address, storageSlotKey) -> { | ||
storageSlotKey.forEach( | ||
(slotKey, slotValue) -> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it guaranteed at this point that for the returned LogTuple
s it is prior != updated
, or must the unchanged values be filtered explicitly?
@@ -134,6 +134,10 @@ public Optional<Bytes> getAccountStateTrieNode( | |||
if (nodeHash.equals(MerkleTrie.EMPTY_TRIE_NODE_HASH)) { | |||
return Optional.of(MerkleTrie.EMPTY_TRIE_NODE); | |||
} else { | |||
/*if (Optional.ofNullable(accountNodes.getIfPresent(nodeHash)).isPresent()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would assume returning preloaded storage slots might be problematic also, isn't it?
// then start from 200 and replay trie logs backwards to 120. We will then PUT new trie nodes | ||
// as if we were at block 120, and after those puts (during mutablestate.persist()) the | ||
// WORLD_BLOCK_NUMBER_KEY, WORLD_BLOCK_HASH_KEY, and WORLD_ROOT_HASH_KEY will be set to 120. | ||
((BonsaiArchiveWorldState) mutableState).createCheckpointState(checkpointBlock); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this process safe in the face of checkpoint interval changing over time?
Changing the checkpoint interval can lead to "stale" flatdb entries or rolling back from a block number for which a checkpoint was never "built" - which at least superficially seems problematic...
This pr is stale because it has been open for 30 days with no activity. |
Superseded by #8918 |
PR description
This PR follows on from the first Bonsai Archive PR and enhances it to provide full state proofs for Bonsai Archive state.
X_BONSAI_ARCHIVE_PROOFS
X_BONSAI_ARCHIVE
andX_BONSAI_ARCHIVE_PROOFS
options are merged into a singleBONSAI_ARCHIVE
data storage format. Currently I think it will be useful to have separate options while in experimental to make it easier to recreate any issues with and without the state proof behaviour.The aim of this feature is to provide feature parity with FOREST DB and allow us to finally start the process of removing FOREST DB from Besu.
Testing
Aside from the updated tests in the PR which exercise the new flat DB format by adding
X_BONSAI_ARCHIVE_PROOFS
to various existing tests, I have run a number of QBFT chains using a combination ofFOREST
,BONSAI
, andX_BONSAI ARCHIVE_PROOFS
nodes and exercised a variety of state update & state proof requests.I have configured a node to sync with Ethereum mainnet and it is currently at block 7m without issues:
In addition to syncing with mainnet, I've created 2 test scripts which exercise
eth_getTransactionCount
,eth_getStorageAt
, andeth_getProof
for known accounts/states in the first 3m blocks. Theeth_getProof
script uses proofs obtained from aFOREST
node synced up to 3+m blocks, and then useseth_getProof
against theBONSAI
archive node to check that the proofs returned byBONSAI
match those returned byFOREST
.Script for eth_getProof testing on mainnet
Script for testing historic account states on mainnet
#!/bin/bash nonceResponseMatches () { echo -n "Checking nonce == $2 for account $3, block $4 - " if [[ "${1^^}" == "${2^^}" ]]; then echo OK else echo "Unexpected JSON/RPC response. $1 != $2" exit 1 fi } storageResponseMatches () { echo -n "Checking storage slot $1 == $3 for account $4, block $5 - " if [[ "${2^^}" == "${3^^}" ]]; then echo OK else echo "Unexpected JSON/RPC response. $2 != $3" exit 1 fi } # Retrive the transaction count for a number of different accounts in the first 1,000,000 blocks of Ethereum L1 # Some of these have been specfically selected for accounts that change several times in a block, or that change in several contiguous blocks. # Block 150003 - 2 transactions from the same sender. Check nonce for blocks 150002, 150003, and 150004 ACCOUNT="0x32Be343B94f860124dC4fEe278FDCBD38C102D88" BLOCK="0x249F2" NONCE=`curl -s -X POST --data '{"jsonrpc":"2.0","method":"eth_getTransactionCount","params":["'$ACCOUNT'","'$BLOCK'"],"id":1}' http://127.0.0.1:8545 | jq .result -r` nonceResponseMatches $NONCE "0x805" $ACCOUNT $BLOCK BLOCK="0x249F3" NONCE=`curl -s -X POST --data '{"jsonrpc":"2.0","method":"eth_getTransactionCount","params":["'$ACCOUNT'","'$BLOCK'"],"id":1}' http://127.0.0.1:8545 | jq .result -r` nonceResponseMatches $NONCE "0x807" $ACCOUNT $BLOCK BLOCK="0x249F4" NONCE=`curl -s -X POST --data '{"jsonrpc":"2.0","method":"eth_getTransactionCount","params":["'$ACCOUNT'","'$BLOCK'"],"id":1}' http://127.0.0.1:8545 | jq .result -r` nonceResponseMatches $NONCE "0x807" $ACCOUNT $BLOCK # Blocks 138719 and 138720 - transactions from the same sender in 2 contiguous blocks. Check blocks 138718, 138719, 138720 and 138721 ACCOUNT="0x1DCb8d1F0FCc8CbC8C2d76528E877F915e299fbE" BLOCK="0x21DDE" NONCE=`curl -s -X POST --data '{"jsonrpc":"2.0","method":"eth_getTransactionCount","params":["'$ACCOUNT'","'$BLOCK'"],"id":1}' http://127.0.0.1:8545 | jq .result -r` nonceResponseMatches $NONCE "0x59" $ACCOUNT $BLOCK BLOCK="0x21DDF" NONCE=`curl -s -X POST --data '{"jsonrpc":"2.0","method":"eth_getTransactionCount","params":["'$ACCOUNT'","'$BLOCK'"],"id":1}' http://127.0.0.1:8545 | jq .result -r` nonceResponseMatches $NONCE "0x5a" $ACCOUNT $BLOCK BLOCK="0x21DE0" NONCE=`curl -s -X POST --data '{"jsonrpc":"2.0","method":"eth_getTransactionCount","params":["'$ACCOUNT'","'$BLOCK'"],"id":1}' http://127.0.0.1:8545 | jq .result -r` nonceResponseMatches $NONCE "0x5b" $ACCOUNT $BLOCK BLOCK="0x21DE1" NONCE=`curl -s -X POST --data '{"jsonrpc":"2.0","method":"eth_getTransactionCount","params":["'$ACCOUNT'","'$BLOCK'"],"id":1}' http://127.0.0.1:8545 | jq .result -r` nonceResponseMatches $NONCE "0x5b" $ACCOUNT $BLOCK # Some storage lookups for slots that are known to change # Blocks 2018260, 2020000, 2300000 for a specific smart contract ACCOUNT="0x684282178b1d61164FEbCf9609cA195BeF9A33B5" BLOCK="0x1ECBD4" SLOT="0x5" STORAGE_VAL=`curl -s -X POST --data '{"jsonrpc":"2.0","method":"eth_getStorageAt","params":["'$ACCOUNT'","'$SLOT'","'$BLOCK'"],"id":1}' http://127.0.0.1:8545 | jq .result -r` storageResponseMatches "$SLOT" $STORAGE_VAL "0x0000000000000000000000000000000000000000000000000000000000000003" $ACCOUNT $BLOCK SLOT="0x7" STORAGE_VAL=`curl -s -X POST --data '{"jsonrpc":"2.0","method":"eth_getStorageAt","params":["'$ACCOUNT'","'$SLOT'","'$BLOCK'"],"id":1}' http://127.0.0.1:8545 | jq .result -r` storageResponseMatches "$SLOT" $STORAGE_VAL "0x0000000000000000000000000000000000000000000000000000000000000001" $ACCOUNT $BLOCK SLOT="0xa" STORAGE_VAL=`curl -s -X POST --data '{"jsonrpc":"2.0","method":"eth_getStorageAt","params":["'$ACCOUNT'","'$SLOT'","'$BLOCK'"],"id":1}' http://127.0.0.1:8545 | jq .result -r` storageResponseMatches "$SLOT" $STORAGE_VAL "0x0000000000000000000000000000000000000000000000000000000000000000" $ACCOUNT $BLOCK BLOCK="0x1ED2A0" SLOT="0x5" STORAGE_VAL=`curl -s -X POST --data '{"jsonrpc":"2.0","method":"eth_getStorageAt","params":["'$ACCOUNT'","'$SLOT'","'$BLOCK'"],"id":1}' http://127.0.0.1:8545 | jq .result -r` storageResponseMatches "$SLOT" $STORAGE_VAL "0x0000000000000000000000000000000000000000000000000000000000000004" $ACCOUNT $BLOCK SLOT="0x7" STORAGE_VAL=`curl -s -X POST --data '{"jsonrpc":"2.0","method":"eth_getStorageAt","params":["'$ACCOUNT'","'$SLOT'","'$BLOCK'"],"id":1}' http://127.0.0.1:8545 | jq .result -r` storageResponseMatches "$SLOT" $STORAGE_VAL "0x0000000000000000000000000000000000000000000000000000000000000001" $ACCOUNT $BLOCK SLOT="0xa" STORAGE_VAL=`curl -s -X POST --data '{"jsonrpc":"2.0","method":"eth_getStorageAt","params":["'$ACCOUNT'","'$SLOT'","'$BLOCK'"],"id":1}' http://127.0.0.1:8545 | jq .result -r` storageResponseMatches "$SLOT" $STORAGE_VAL "0x0000000000000000000000000000000000000000000000000000000000000000" $ACCOUNT $BLOCK BLOCK="0x231860" SLOT="0x5" STORAGE_VAL=`curl -s -X POST --data '{"jsonrpc":"2.0","method":"eth_getStorageAt","params":["'$ACCOUNT'","'$SLOT'","'$BLOCK'"],"id":1}' http://127.0.0.1:8545 | jq .result -r` storageResponseMatches "$SLOT" $STORAGE_VAL "0x0000000000000000000000000000000000000000000000000000000000000005" $ACCOUNT $BLOCK SLOT="0x7" STORAGE_VAL=`curl -s -X POST --data '{"jsonrpc":"2.0","method":"eth_getStorageAt","params":["'$ACCOUNT'","'$SLOT'","'$BLOCK'"],"id":1}' http://127.0.0.1:8545 | jq .result -r` storageResponseMatches "$SLOT" $STORAGE_VAL "0x0000000000000000000000000000000000000000000000000000000000000001" $ACCOUNT $BLOCK SLOT="0xa" STORAGE_VAL=`curl -s -X POST --data '{"jsonrpc":"2.0","method":"eth_getStorageAt","params":["'$ACCOUNT'","'$SLOT'","'$BLOCK'"],"id":1}' http://127.0.0.1:8545 | jq .result -r` storageResponseMatches "$SLOT" $STORAGE_VAL "0x0000000000000000000000000000000000000000000000000000000000000001" $ACCOUNT $BLOCK # Some other random checks for nonce on accounts at later blocks # Block 2000000 ACCOUNT="0x32Be343B94f860124dC4fEe278FDCBD38C102D88" BLOCK="0x1E8480" NONCE=`curl -s -X POST --data '{"jsonrpc":"2.0","method":"eth_getTransactionCount","params":["'$ACCOUNT'","'$BLOCK'"],"id":1}' http://127.0.0.1:8545 | jq .result -r` nonceResponseMatches $NONCE "0x1EFC6" $ACCOUNT $BLOCK # Block 3000000 ACCOUNT="0xEA674fdDe714fd979de3EdF0F56AA9716B898ec8" BLOCK="0x2DC6C0" NONCE=`curl -s -X POST --data '{"jsonrpc":"2.0","method":"eth_getTransactionCount","params":["'$ACCOUNT'","'$BLOCK'"],"id":1}' http://127.0.0.1:8545 | jq .result -r` nonceResponseMatches $NONCE "0x10AA05" $ACCOUNT $BLOCK exit 0