Skip to content

Conversation

JonathanOppenheimer
Copy link
Member

Why this should be merged

There are packages in subnet-evm and coreth that share a lot of functionality / are mirrored. As has been discussed as an evm team wide effort, we are working to uplift these packages to AvalancheGo to prevent the duplicative maintenance of two sets of the same code. This particular package, database is a relatively easy lift.

How this was tested

This is currently 'dead' code; after a new AvalancheGo release is dropped, we can use the code in the evm repositories.

Need to be documented in RELEASES.md?

No

@JonathanOppenheimer JonathanOppenheimer self-assigned this Sep 24, 2025
@Copilot Copilot AI review requested due to automatic review settings September 24, 2025 16:35
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR uplifts the database package from EVM repositories (subnet-evm and coreth) to AvalancheGo to eliminate code duplication and centralize maintenance. This is part of a team-wide effort to consolidate shared functionality between repositories.

Key changes:

  • Adds a new wrapped_database.go file containing database wrapper implementations
  • Implements ethdb.KeyValueStore interface wrapper for avalanchego database types
  • Provides batch operations wrapper for database operations

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

JonathanOppenheimer and others added 2 commits September 24, 2025 16:10
Co-authored-by: rodrigo <77309055+RodrigoVillar@users.noreply.github.com>
Signed-off-by: Jonathan Oppenheimer <147infiniti@gmail.com>
@JonathanOppenheimer
Copy link
Member Author

Thanks for the suggestions rodrigo :)

@JonathanOppenheimer JonathanOppenheimer changed the title uplift: Add database package from evm repositories uplift: add database package from evm repositories Sep 24, 2025

func WrapDatabase(db database.Database) ethdb.KeyValueStore { return ethDBWrapper{db} }

type ethDBWrapper struct{ database.Database }
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. nit: I would just call this database or db or something. It's implied that this is an eth-compatible db because we're in the evm package. It's also obvious from looking at the struct definition that this is a wrapper pattern.
  2. avoid embed if we can, see later comment

Copy link
Member Author

@JonathanOppenheimer JonathanOppenheimer Oct 1, 2025

Choose a reason for hiding this comment

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

  1. We can't do database (it's the import) or db bc of the intervening var definition. I'd say we do ethdb, but that's also an import. Any other suggestions?
  2. done

Copy link
Contributor

@joshua-kim joshua-kim Oct 1, 2025

Choose a reason for hiding this comment

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

You can alias imports if there's a namespace collision (you could call database avalanchegodatabase or avalanchegodb or something)


// TODO: propagate size through avalanchego Database interface
func (db ethDBWrapper) NewBatchWithSize(int) ethdb.Batch {
return ethBatchWrapper{db.Database.NewBatch()}
Copy link
Contributor

Choose a reason for hiding this comment

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

We could just return db.NewBatch() here

Copy link
Member Author

Choose a reason for hiding this comment

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

If we do that, then we does not implement ethdb.KeyValueStore:

		have NewBatch() "github.com/ava-labs/avalanchego/database".Batch
		want NewBatch() ethdb.Batch

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.

3 participants