Skip to content

Conversation

powerslider
Copy link

Why this should be merged

Check #4386

How this works

  • Move plugin/evm/customrawdb in coreth to vms/evm/sync in avalanchego as part of state sync code migration effort.

How this was tested

Existing UT that come with the migrated code.

Need to be documented in RELEASES.md?

no

resolves #4386

Signed-off-by: Tsvetan Dimitrov (tsvetan.dimitrov23@gmail.com)

- Move `plugin/evm/customrawdb` in `coreth` to `vms/evm/sync` in
  `avalanchego` as part of state sync code migration effort.

resolves #4386

Signed-off-by: Tsvetan Dimitrov (tsvetan.dimitrov23@gmail.com)

// InspectDatabase traverses the entire database and checks the size
// of all different categories of data.
func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like dead code, why do we have this?

Copy link
Author

Choose a reason for hiding this comment

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

It is used only in database_ext_test.go, so it is a bit unnecessary to be present here. I will check though historically why it was added in the first place since I am not the original author.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we have this file? This contains dead code/a function that isn't actually a test.

Copy link
Author

Choose a reason for hiding this comment

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

Yes, I agree with this. I will check why this was historically added in the first place, but we can definitely remove it from here.

Copy link
Contributor

Choose a reason for hiding this comment

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

What does the _ext suffix on these files mean? Should we remove it?

}

// IterateAccountSnapshots returns an iterator for walking all of the accounts in the snapshot
func IterateAccountSnapshots(db ethdb.Iteratee) ethdb.Iterator {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Maybe name this NewAccountSnapshotsIterator? IterateAccountSnapshots makes it sound like this function is iterating over the database when it is just a constructor for an iterator.

Referencing rawdb - I can't tell what the intended convention is because they also do something similar by mixing the two naming styles (ref).

}

// AddCodeToFetch adds a marker that we need to fetch the code for `hash`.
func AddCodeToFetch(db ethdb.KeyValueWriter, hash common.Hash) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Naming in this package is inconsistent - we're calling this Add but the other apis are all Write* for db writes.

}

// packSyncSegmentKey packs root and account into a key for storage in db.
func packSyncSegmentKey(root common.Hash, start common.Hash) []byte {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we refactor this into a separate function if it's only used in one place, and the call-site is basically a direct pass through into this?

}

// packSyncStorageTrieKey packs root and account into a key for storage in db.
func packSyncStorageTrieKey(root common.Hash, account common.Hash) []byte {
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar comment w.r.t refactored function

"github.com/stretchr/testify/require"
)

func TestClearPrefix(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like ClearAllSyncSegments is the only function tested (and that this test name is wrong) - could we add coverage on this package api?

"github.com/ava-labs/avalanchego/utils/wrappers"
)

var (
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we group all package-level global vars under a single block? If we want to group them by intent, we can add in-line comments

var FirewoodScheme = "firewood"

// upgradeConfigKey = upgradeConfigPrefix + hash
func upgradeConfigKey(hash common.Hash) []byte {
Copy link
Contributor

@joshua-kim joshua-kim Oct 8, 2025

Choose a reason for hiding this comment

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

This is a weird place for this function to live - it's defined in a file that's not close to where it's used. I think the file structure of this package more generally speaking could be improved - Go code usually will place code into files where there are clear boundaries between abstractions (big files with multiple types are fine). It's not clear to me what this file actually owns/represents.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

Migrate customrawdb package from coreth to avalanchego
2 participants