diff --git a/arbitrum/apibackend.go b/arbitrum/apibackend.go index 35d6c7dac914..795ef87ac21b 100644 --- a/arbitrum/apibackend.go +++ b/arbitrum/apibackend.go @@ -55,6 +55,10 @@ func (a *APIBackend) GetAPIs() []rpc.API { return apis } +func (a *APIBackend) blockChain() *core.BlockChain { + return a.b.publisher.BlockChain() +} + // General Ethereum API func (a *APIBackend) SyncProgress() ethereum.SyncProgress { panic("not implemented") // TODO: Implement @@ -99,13 +103,13 @@ func (a *APIBackend) SetHead(number uint64) { func (a *APIBackend) HeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Header, error) { if number == rpc.LatestBlockNumber { - return a.b.blockChain.CurrentBlock().Header(), nil + return a.blockChain().CurrentBlock().Header(), nil } - return a.b.blockChain.GetHeaderByNumber(uint64(number.Int64())), nil + return a.blockChain().GetHeaderByNumber(uint64(number.Int64())), nil } func (a *APIBackend) HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error) { - return a.b.blockChain.GetHeaderByHash(hash), nil + return a.blockChain().GetHeaderByHash(hash), nil } func (a *APIBackend) HeaderByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*types.Header, error) { @@ -121,19 +125,19 @@ func (a *APIBackend) HeaderByNumberOrHash(ctx context.Context, blockNrOrHash rpc } func (a *APIBackend) CurrentHeader() *types.Header { - return a.b.blockChain.CurrentHeader() + return a.blockChain().CurrentHeader() } func (a *APIBackend) CurrentBlock() *types.Block { - return a.b.blockChain.CurrentBlock() + return a.blockChain().CurrentBlock() } func (a *APIBackend) BlockByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Block, error) { - return a.b.blockChain.GetBlockByNumber(uint64(number.Int64())), nil + return a.blockChain().GetBlockByNumber(uint64(number.Int64())), nil } func (a *APIBackend) BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error) { - return a.b.blockChain.GetBlockByHash(hash), nil + return a.blockChain().GetBlockByHash(hash), nil } func (a *APIBackend) BlockByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*types.Block, error) { @@ -155,7 +159,7 @@ func (a *APIBackend) stateAndHeaderFromHeader(header *types.Header, err error) ( if header == nil { return nil, nil, errors.New("header not found") } - state, err := a.b.blockChain.StateAt(header.Root) + state, err := a.blockChain().StateAt(header.Root) return state, header, err } @@ -168,33 +172,33 @@ func (a *APIBackend) StateAndHeaderByNumberOrHash(ctx context.Context, blockNrOr } func (a *APIBackend) GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error) { - return a.b.blockChain.GetReceiptsByHash(hash), nil + return a.blockChain().GetReceiptsByHash(hash), nil } func (a *APIBackend) GetTd(ctx context.Context, hash common.Hash) *big.Int { - return a.b.blockChain.GetTdByHash(hash) + return a.blockChain().GetTdByHash(hash) } func (a *APIBackend) GetEVM(ctx context.Context, msg core.Message, state *state.StateDB, header *types.Header, vmConfig *vm.Config) (*vm.EVM, func() error, error) { vmError := func() error { return nil } if vmConfig == nil { - vmConfig = a.b.blockChain.GetVMConfig() + vmConfig = a.blockChain().GetVMConfig() } txContext := core.NewEVMTxContext(msg) - context := core.NewEVMBlockContext(header, a.b.blockChain, nil) - return vm.NewEVM(context, txContext, state, a.b.blockChain.Config(), *vmConfig), vmError, nil + context := core.NewEVMBlockContext(header, a.blockChain(), nil) + return vm.NewEVM(context, txContext, state, a.blockChain().Config(), *vmConfig), vmError, nil } func (a *APIBackend) SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subscription { - return a.b.blockChain.SubscribeChainEvent(ch) + return a.blockChain().SubscribeChainEvent(ch) } func (a *APIBackend) SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event.Subscription { - return a.b.blockChain.SubscribeChainHeadEvent(ch) + return a.blockChain().SubscribeChainHeadEvent(ch) } func (a *APIBackend) SubscribeChainSideEvent(ch chan<- core.ChainSideEvent) event.Subscription { - return a.b.blockChain.SubscribeChainSideEvent(ch) + return a.blockChain().SubscribeChainSideEvent(ch) } // Transaction pool API @@ -249,7 +253,7 @@ func (a *APIBackend) ServiceFilter(ctx context.Context, session *bloombits.Match } func (a *APIBackend) SubscribeLogsEvent(ch chan<- []*types.Log) event.Subscription { - return a.b.blockChain.SubscribeLogsEvent(ch) + return a.blockChain().SubscribeLogsEvent(ch) } func (a *APIBackend) SubscribePendingLogsEvent(ch chan<- []*types.Log) event.Subscription { @@ -258,13 +262,13 @@ func (a *APIBackend) SubscribePendingLogsEvent(ch chan<- []*types.Log) event.Sub } func (a *APIBackend) SubscribeRemovedLogsEvent(ch chan<- core.RemovedLogsEvent) event.Subscription { - return a.b.blockChain.SubscribeRemovedLogsEvent(ch) + return a.blockChain().SubscribeRemovedLogsEvent(ch) } func (a *APIBackend) ChainConfig() *params.ChainConfig { - return a.b.blockChain.Config() + return a.blockChain().Config() } func (a *APIBackend) Engine() consensus.Engine { - return a.b.blockChain.Engine() + return a.blockChain().Engine() } diff --git a/arbitrum/arbos_interface.go b/arbitrum/arbos_interface.go index 6d6a2a903a35..25ee04720dcd 100644 --- a/arbitrum/arbos_interface.go +++ b/arbitrum/arbos_interface.go @@ -1,9 +1,11 @@ package arbitrum import ( + "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/types" ) type TransactionPublisher interface { PublishTransaction(tx *types.Transaction) error + BlockChain() *core.BlockChain } diff --git a/arbitrum/backend.go b/arbitrum/backend.go index 9033218a3779..56a75de30d4d 100644 --- a/arbitrum/backend.go +++ b/arbitrum/backend.go @@ -4,7 +4,6 @@ import ( "math/big" "github.com/ethereum/go-ethereum/core" - "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/eth/ethconfig" "github.com/ethereum/go-ethereum/ethdb" @@ -14,7 +13,6 @@ import ( type Backend struct { publisher TransactionPublisher - blockChain *core.BlockChain stack *node.Node chainId *big.Int apiBackend *APIBackend @@ -32,7 +30,6 @@ type Backend struct { func NewBackend(stack *node.Node, config *ethconfig.Config, ethDatabase ethdb.Database, blockChain *core.BlockChain, chainId *big.Int, publisher TransactionPublisher) (*Backend, error) { backend := &Backend{ publisher: publisher, - blockChain: blockChain, stack: stack, chainId: chainId, ethConfig: config, @@ -59,15 +56,12 @@ func (b *Backend) SubscribeNewTxsEvent(ch chan<- core.NewTxsEvent) event.Subscri return b.scope.Track(b.txFeed.Subscribe(ch)) } -func (b *Backend) enqueueBlock(block *types.Block, reciepts types.Receipts, state *state.StateDB) { - if block == nil { - return - } - logs := make([]*types.Log, 0) - for _, receipt := range reciepts { - logs = append(logs, receipt.Logs...) - } - b.blockChain.WriteBlockWithState(block, reciepts, logs, state, true) +func (b *Backend) Stack() *node.Node { + return b.stack +} + +func (b *Backend) Publisher() TransactionPublisher { + return b.publisher } //TODO: this is used when registering backend as lifecycle in stack @@ -78,7 +72,6 @@ func (b *Backend) Start() error { func (b *Backend) Stop() error { b.scope.Close() - b.blockChain.Stop() return nil }