diff --git a/blockchain/blockchain.go b/blockchain/blockchain.go index dc13271f7d6901467da4510830860c04cb504af1..a644988f4ac02e03420fcdfe7f3eddfdf91ee01e 100644 --- a/blockchain/blockchain.go +++ b/blockchain/blockchain.go @@ -100,12 +100,12 @@ type PersistedState struct { } func LoadOrNewBlockchain(db dbm.DB, genesisDoc *genesis.GenesisDoc, - logger *logging.Logger) (*blockchain, error) { + logger *logging.Logger) (MutableBlockchain, error) { logger = logger.WithScope("LoadOrNewBlockchain") logger.InfoMsg("Trying to load blockchain state from database", "database_key", stateKey) - blockchain, err := LoadBlockchain(db) + blockchain, err := loadBlockchain(db) if err != nil { return nil, fmt.Errorf("error loading blockchain state from database: %v", err) } @@ -120,11 +120,11 @@ func LoadOrNewBlockchain(db dbm.DB, genesisDoc *genesis.GenesisDoc, } logger.InfoMsg("No existing blockchain state found in database, making new blockchain") - return NewBlockchain(db, genesisDoc), nil + return newBlockchain(db, genesisDoc), nil } // Pointer to blockchain state initialised from genesis -func NewBlockchain(db dbm.DB, genesisDoc *genesis.GenesisDoc) *blockchain { +func newBlockchain(db dbm.DB, genesisDoc *genesis.GenesisDoc) *blockchain { var validators []acm.Validator for _, gv := range genesisDoc.Validators { validators = append(validators, acm.ConcreteValidator{ @@ -141,7 +141,7 @@ func NewBlockchain(db dbm.DB, genesisDoc *genesis.GenesisDoc) *blockchain { } } -func LoadBlockchain(db dbm.DB) (*blockchain, error) { +func loadBlockchain(db dbm.DB) (*blockchain, error) { buf := db.Get(stateKey) if len(buf) == 0 { return nil, nil @@ -150,7 +150,7 @@ func LoadBlockchain(db dbm.DB) (*blockchain, error) { if err != nil { return nil, err } - blockchain := NewBlockchain(db, &persistedState.GenesisDoc) + blockchain := newBlockchain(db, &persistedState.GenesisDoc) blockchain.lastBlockHeight = persistedState.LastBlockHeight blockchain.appHashAfterLastBlock = persistedState.AppHashAfterLastBlock return blockchain, nil diff --git a/execution/execution_test.go b/execution/execution_test.go index d1aa94547447bcc13f4713414237c51eb52b4cd5..b5ff92b288f58b3f132ffd17a007eeff62712c1d 100644 --- a/execution/execution_test.go +++ b/execution/execution_test.go @@ -127,10 +127,16 @@ func makeUsers(n int) []acm.AddressableSigner { } return users } +func newBlockchain(genesisDoc *genesis.GenesisDoc) bcm.MutableBlockchain { + testDB := dbm.NewDB("test", dbBackend, ".") + bc, _ := bcm.LoadOrNewBlockchain(testDB, testGenesisDoc, logger) + + return bc +} func makeExecutor(state *State) *executor { return newExecutor("makeExecutorCache", true, state, testChainID, - bcm.NewBlockchain(nil, testGenesisDoc), event.NewEmitter(logger), logger) + newBlockchain(testGenesisDoc), event.NewEmitter(logger), logger) } func newBaseGenDoc(globalPerm, accountPerm ptypes.AccountPermissions) genesis.GenesisDoc { @@ -1032,7 +1038,7 @@ func TestNameTxs(t *testing.T) { state.Save() txs.MinNameRegistrationPeriod = 5 - blockchain := bcm.NewBlockchain(nil, testGenesisDoc) + blockchain := newBlockchain(testGenesisDoc) startingBlock := blockchain.LastBlockHeight() // try some bad names. these should all fail @@ -1646,7 +1652,7 @@ func TestSelfDestruct(t *testing.T) { require.NoError(t, tx.Sign(testChainID, privAccounts[0])) // we use cache instead of execTxWithState so we can run the tx twice - exe := NewBatchCommitter(state, testChainID, bcm.NewBlockchain(nil, testGenesisDoc), event.NewNoOpPublisher(), logger) + exe := NewBatchCommitter(state, testChainID, newBlockchain(testGenesisDoc), event.NewNoOpPublisher(), logger) if err := exe.Execute(tx); err != nil { t.Errorf("Got error in executing call transaction, %v", err) } @@ -1687,7 +1693,7 @@ func execTxWithStateAndBlockchain(state *State, tip bcm.Tip, tx txs.Tx) error { } func execTxWithState(state *State, tx txs.Tx) error { - return execTxWithStateAndBlockchain(state, bcm.NewBlockchain(nil, testGenesisDoc), tx) + return execTxWithStateAndBlockchain(state, newBlockchain(testGenesisDoc), tx) } func commitNewBlock(state *State, blockchain bcm.MutableBlockchain) {