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

Merkle-ize X-Chain State #3732

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Merkle-ize X-Chain State #3732

wants to merge 1 commit into from

Conversation

joshua-kim
Copy link
Contributor

@joshua-kim joshua-kim commented Feb 20, 2025

Why this should be merged

Implements a database migration from the legacy database format into a database format that supports a merkle-ized prefix of state

How this works

Changes db schema

How this was tested

Added a migration unit test + tested state migration on Fuji

[03-20|16:01:06.597] INFO <X Chain> avm/vm.go:173 VM config initialized {"config": {"network":{"max-validator-set-staleness":60000000000,"target-gossip-size":20480,"push-gossip-percent-stake":0.9,"push-gossip-num-validators":100,"push-gossip-num-peers":0,"push-regossip-num-validators":10,"push-regossip-num-peers":0,"push-gossip-discarded-cache-size":16384,"push-gossip-max-regossip-frequency":30000000000,"push-gossip-frequency":500000000,"pull-gossip-poll-size":1,"pull-gossip-frequency":1500000000,"pull-gossip-throttling-period":10000000000,"pull-gossip-throttling-limit":2,"expected-bloom-filter-elements":8192,"expected-bloom-filter-false-positive-probability":0.01,"max-bloom-filter-false-positive-probability":0.05},"index-transactions":false,"index-allow-incomplete":false,"checksums-enabled":false}}
[03-20|16:01:06.597] INFO <X Chain> avm/vm.go:598 fee asset is established {"alias": "AVAX", "assetID": "U8iRqJoiJm8xZHAacmvYyZVwqQx6uDNtQeP3CQ6fcgQk3JqnK"}
[03-20|16:01:06.597] INFO <X Chain> avm/vm.go:257 address transaction indexing is disabled
[03-20|16:01:06.599] INFO <X Chain> snowman/engine.go:96 initializing consensus engine
[03-20|16:01:06.599] INFO <X Chain> bootstrap/bootstrapper.go:320 starting bootstrap
[03-20|16:01:06.601] INFO <X Chain> bootstrap/bootstrapper.go:600 executing transactions
[03-20|16:01:06.601] INFO <X Chain> queue/jobs.go:223 executed operations {"numExecuted": 0}
[03-20|16:01:06.601] INFO <X Chain> bootstrap/bootstrapper.go:612 executing vertices
[03-20|16:01:06.601] INFO <X Chain> queue/jobs.go:223 executed operations {"numExecuted": 0}
[03-20|16:01:06.603] INFO <X Chain> avm/state_migration.go:143 starting state migration
[03-20|16:04:53.784] INFO <X Chain> avm/state_migration.go:321 migration complete
[03-20|16:04:53.790] INFO <X Chain> proposervm/vm.go:209 initialized proposervm {"state": "after fork", "forkHeight": 1, "lastAcceptedHeight": 32356}
[03-20|16:04:53.790] INFO <X Chain> bootstrap/bootstrapper.go:182 starting bootstrapper {"lastAcceptedID": "8o6VfSzPHhjLXwr7FEZDxuVAwXYVCx6dP7vrwLoW9mwYRPZi4", "lastAcceptedHeight": 32356}
[03-20|16:05:42.318] INFO <X Chain> bootstrap/bootstrapper.go:387 starting to fetch blocks {"numKnownBlocks": 99, "numAcceptedBlocks": 1, "numMissingBlocks": 100}
[03-20|16:05:42.857] INFO <X Chain> bootstrap/storage.go:194 executing blocks {"numToExecute": 45}
[03-20|16:05:43.116] INFO <X Chain> bootstrap/storage.go:186 executed blocks {"numExecuted": 45, "numToExecute": 45, "halted": false, "duration": "258.784792ms"}

Need to be documented in RELEASES.md?

Yes

@joshua-kim joshua-kim changed the title X chain merkle db Merkle-ize X-Chain State Feb 20, 2025
@joshua-kim joshua-kim changed the base branch from master to merkle-db-config March 4, 2025 22:37
@joshua-kim joshua-kim force-pushed the x-chain-merkle-db branch 3 times, most recently from e89db38 to 20ae963 Compare March 6, 2025 16:27
@joshua-kim joshua-kim force-pushed the x-chain-merkle-db branch 7 times, most recently from db6f8b7 to 0505956 Compare March 11, 2025 18:52
@@ -38,6 +39,21 @@ func New() *Database {
return NewWithSize(DefaultSize)
}

// Copy returns a Database with the same key-value pairs as db
func Copy(db *Database) (*Database, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need this utility to be able to copy the memdb between VM instances, since closing a database makes it so that it's unusable afterwards.

@@ -38,7 +42,7 @@ var (
timestampKey = []byte{0x01}
lastAcceptedKey = []byte{0x02}
Copy link
Contributor Author

@joshua-kim joshua-kim Mar 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't needed as part of this PR, but we could change these from bytes to plain strings (i.e "is_initialized", "timestamp", etc). I don't think the overhead is an issue + it makes it much reason about when reading it in the debugger.

parser block.Parser
db *versiondb.Database

modifiedUTXOs map[ids.ID]*avax.UTXO // map of modified UTXOID -> *UTXO if the UTXO is nil, it has been removed
utxoDB database.Database
utxoState avax.UTXOState
// TODO un-export databases post-migration
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another idea is to just make the calling code use NewWithFormat instead of exporting these dbs

@joshua-kim joshua-kim self-assigned this Mar 18, 2025
@joshua-kim joshua-kim added the vm This involves virtual machines label Mar 18, 2025
@joshua-kim joshua-kim marked this pull request as ready for review March 18, 2025 20:31
@joshua-kim joshua-kim force-pushed the x-chain-merkle-db branch 2 times, most recently from 4b94f56 to c555608 Compare March 20, 2025 19:43
s.blockIDDB.Close(),
s.blockDB.Close(),
s.UTXODB.Close(),
s.UTXOIndexDB.Close(),
Copy link
Contributor Author

@joshua-kim joshua-kim Mar 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously the avax package owned this db but it didn't close it... so this is a behavior change.

@joshua-kim joshua-kim force-pushed the merkle-db-config branch 2 times, most recently from 8955b58 to a4d93f3 Compare March 25, 2025 02:30
@joshua-kim joshua-kim force-pushed the x-chain-merkle-db branch 3 times, most recently from 9e8a483 to ea6e1ec Compare March 25, 2025 02:47
@joshua-kim joshua-kim force-pushed the x-chain-merkle-db branch 4 times, most recently from d9fd467 to 22b8d5a Compare March 25, 2025 05:14
Base automatically changed from merkle-db-config to master March 25, 2025 16:16
Signed-off-by: Joshua Kim <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
vm This involves virtual machines
Projects
Status: In Review 👀
Development

Successfully merging this pull request may close these issues.

1 participant