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

add standalone dbs and configs #1354

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
5 changes: 3 additions & 2 deletions plugin/evm/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ func TestHandlePrecompileAccept(t *testing.T) {

db := rawdb.NewMemoryDatabase()
vm := &VM{
chaindb: db,
chainConfig: params.TestChainConfig,
chaindb: db,
chainConfig: params.TestChainConfig,
skipStandaloneDB: true,
}

precompileAddr := common.Address{0x05}
Expand Down
27 changes: 27 additions & 0 deletions plugin/evm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"time"

"github.com/ava-labs/avalanchego/database/pebbledb"
"github.com/ava-labs/subnet-evm/core/txpool/legacypool"
"github.com/ava-labs/subnet-evm/eth"
"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -60,8 +61,11 @@ const (
// - state sync time: ~6 hrs.
defaultStateSyncMinBlocks = 300_000
defaultStateSyncRequestSize = 1024 // the number of key/values to ask peers for per request
defaultDBType = pebbledb.Name
)

type PBool bool

var (
defaultEnabledAPIs = []string{
"eth",
Expand Down Expand Up @@ -225,6 +229,14 @@ type Config struct {

// RPC settings
HttpBodyLimit uint64 `json:"http-body-limit"`

// Database settings
UseStandaloneDatabase *PBool `json:"use-standalone-database"`
DatabaseConfigContent string `json:"database-config"`
DatabaseConfigFile string `json:"database-config-file"`
DatabaseType string `json:"database-type"`
DatabasePath string `json:"database-path"`
DatabaseReadOnly bool `json:"database-read-only"`
}

// EthAPIs returns an array of strings representing the Eth APIs that should be enabled
Expand Down Expand Up @@ -284,6 +296,7 @@ func (c *Config) SetDefaults() {
c.StateSyncRequestSize = defaultStateSyncRequestSize
c.AllowUnprotectedTxHashes = defaultAllowUnprotectedTxHashes
c.AcceptedCacheSize = defaultAcceptedCacheSize
c.DatabaseType = defaultDBType
}

func (d *Duration) UnmarshalJSON(data []byte) (err error) {
Expand Down Expand Up @@ -338,3 +351,17 @@ func (c *Config) Deprecate() string {

return msg
}

func (p *PBool) String() string {
if p == nil {
return "nil"
}
return fmt.Sprintf("%t", *p)
}

func (p *PBool) Bool() bool {
if p == nil {
return false
}
return bool(*p)
}
12 changes: 7 additions & 5 deletions plugin/evm/syncervm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ func TestStateSyncToggleEnabledToDisabled(t *testing.T) {
test.responseIntercept = nil
test.expectedErr = nil

syncDisabledVM := &VM{}
syncDisabledVM := &VM{
skipStandaloneDB: true,
}
appSender := &enginetest.Sender{T: t}
appSender.SendAppGossipF = func(context.Context, commonEng.SendConfig, []byte) error { return nil }
appSender.SendAppRequestF = func(ctx context.Context, nodeSet set.Set[ids.NodeID], requestID uint32, request []byte) error {
Expand Down Expand Up @@ -195,7 +197,9 @@ func TestStateSyncToggleEnabledToDisabled(t *testing.T) {
syncDisabledVM.blockChain.DrainAcceptorQueue()

// Create a new VM from the same database with state sync enabled.
syncReEnabledVM := &VM{}
syncReEnabledVM := &VM{
skipStandaloneDB: true,
}
// Enable state sync in configJSON
configJSON := fmt.Sprintf(
`{"state-sync-enabled":true, "state-sync-min-blocks":%d}`,
Expand Down Expand Up @@ -273,9 +277,7 @@ func TestVMShutdownWhileSyncing(t *testing.T) {
}

func createSyncServerAndClientVMs(t *testing.T, test syncTest, numBlocks int) *syncVMSetup {
var (
require = require.New(t)
)
require := require.New(t)
// configure [serverVM]
_, serverVM, _, serverAppSender := GenesisVM(t, true, genesisJSONLatest, "", "")
t.Cleanup(func() {
Expand Down
5 changes: 4 additions & 1 deletion plugin/evm/tx_gossip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ func TestEthTxGossip(t *testing.T) {
SentAppResponse: make(chan []byte, 1),
}
vm := &VM{
p2pSender: responseSender,
p2pSender: responseSender,
skipStandaloneDB: true,
}

require.NoError(vm.Initialize(
Expand Down Expand Up @@ -169,6 +170,7 @@ func TestEthTxPushGossipOutbound(t *testing.T) {

vm := &VM{
ethTxPullGossiper: gossip.NoOpGossiper{},
skipStandaloneDB: true,
}

require.NoError(vm.Initialize(
Expand Down Expand Up @@ -222,6 +224,7 @@ func TestEthTxPushGossipInbound(t *testing.T) {
sender := &enginetest.Sender{}
vm := &VM{
ethTxPullGossiper: gossip.NoOpGossiper{},
skipStandaloneDB: true,
}

require.NoError(vm.Initialize(
Expand Down
Loading
Loading