Skip to content

InboxState APIs #6

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

Merged
merged 13 commits into from
Oct 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions arbitrum/arbos_interface.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package arbitrum

import (
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
)

type ArbosWrapper interface {
BuildBlock(force bool) (*types.Block, types.Receipts, *state.StateDB)

EnqueueSequencerTx(tx *types.Transaction) error
type TransactionPublisher interface {
PublishTransaction(tx *types.Transaction) error
}
28 changes: 4 additions & 24 deletions arbitrum/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

type Backend struct {
arbos ArbosWrapper
publisher TransactionPublisher
blockChain *core.BlockChain
stack *node.Node
chainId *big.Int
Expand All @@ -29,9 +29,9 @@ type Backend struct {
chanNewBlock chan struct{} //create new L2 block unless empty
}

func NewBackend(stack *node.Node, config *ethconfig.Config, ethDatabase ethdb.Database, blockChain *core.BlockChain, chainId *big.Int, arbos ArbosWrapper) (*Backend, error) {
func NewBackend(stack *node.Node, config *ethconfig.Config, ethDatabase ethdb.Database, blockChain *core.BlockChain, chainId *big.Int, publisher TransactionPublisher) (*Backend, error) {
backend := &Backend{
arbos: arbos,
publisher: publisher,
blockChain: blockChain,
stack: stack,
chainId: chainId,
Expand All @@ -42,7 +42,6 @@ func NewBackend(stack *node.Node, config *ethconfig.Config, ethDatabase ethdb.Da
chanNewBlock: make(chan struct{}, 1),
}
stack.RegisterLifecycle(backend)
go backend.segmentQueueRoutine()

createRegisterAPIBackend(backend)
return backend, nil
Expand All @@ -53,12 +52,7 @@ func (b *Backend) APIBackend() *APIBackend {
}

func (b *Backend) EnqueueL2Message(tx *types.Transaction) error {
b.chanTxs <- tx
return nil
}

func (b *Backend) CloseBlock() {
b.chanNewBlock <- struct{}{}
return b.publisher.PublishTransaction(tx)
}

func (b *Backend) SubscribeNewTxsEvent(ch chan<- core.NewTxsEvent) event.Subscription {
Expand All @@ -76,20 +70,6 @@ func (b *Backend) enqueueBlock(block *types.Block, reciepts types.Receipts, stat
b.blockChain.WriteBlockWithState(block, reciepts, logs, state, true)
}

func (b *Backend) segmentQueueRoutine() {
for {
select {
case tx := <-b.chanTxs:
b.txFeed.Send(core.NewTxsEvent{Txs: []*types.Transaction{tx}})
b.arbos.EnqueueSequencerTx(tx)
case <-b.chanNewBlock:
b.enqueueBlock(b.arbos.BuildBlock(true))
case <-b.chanClose:
return
}
}
}

//TODO: this is used when registering backend as lifecycle in stack
func (b *Backend) Start() error {
return nil
Expand Down
12 changes: 8 additions & 4 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -768,10 +768,7 @@ func (bc *BlockChain) ExportN(w io.Writer, first uint64, last uint64) error {
// or if they are on a different side chain.
//
// Note, this function assumes that the `mu` mutex is held!
func (bc *BlockChain) writeHeadBlock(block *types.Block) {
// If the block is on a side chain or an unknown one, force other heads onto it too
updateHeads := rawdb.ReadCanonicalHash(bc.db, block.NumberU64()) != block.Hash()

func (bc *BlockChain) writeHeadBlockImpl(block *types.Block, updateHeads bool) {
// Add the block to the canonical chain number scheme and mark as the head
batch := bc.db.NewBatch()
rawdb.WriteCanonicalHash(batch, block.Hash(), block.NumberU64())
Expand All @@ -797,6 +794,13 @@ func (bc *BlockChain) writeHeadBlock(block *types.Block) {
headBlockGauge.Update(int64(block.NumberU64()))
}

func (bc *BlockChain) writeHeadBlock(block *types.Block) {
// If the block is on a side chain or an unknown one, force other heads onto it too
updateHeads := rawdb.ReadCanonicalHash(bc.db, block.NumberU64()) != block.Hash()

bc.writeHeadBlockImpl(block, updateHeads)
}

// Genesis retrieves the chain's genesis block.
func (bc *BlockChain) Genesis() *types.Block {
return bc.genesisBlock
Expand Down
34 changes: 34 additions & 0 deletions core/blockchain_arbitrum.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2021 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.

// Package core implements the Ethereum consensus protocol.
package core

import "github.com/ethereum/go-ethereum/core/types"

func (bc *BlockChain) ReorgToOldBlock(newHead *types.Block) error {
bc.wg.Add(1)
bc.chainmu.Lock()
defer bc.wg.Done()
defer bc.chainmu.Unlock()
oldHead := bc.CurrentBlock()
bc.writeHeadBlockImpl(newHead, true)
err := bc.reorg(oldHead, newHead)
if err != nil {
return err
}
return nil
}
6 changes: 5 additions & 1 deletion core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,12 @@ var CreateTxProcessingHook func(msg Message, evm *vm.EVM) TxProcessingHook

// NewStateTransition initialises and returns a new state transition object.
func NewStateTransition(evm *vm.EVM, msg Message, gp *GasPool) *StateTransition {
var processingHook TxProcessingHook
if CreateTxProcessingHook != nil {
processingHook = CreateTxProcessingHook(msg, evm)
}
return &StateTransition{
processingHook: CreateTxProcessingHook(msg, evm),
processingHook: processingHook,

gp: gp,
evm: evm,
Expand Down
2 changes: 2 additions & 0 deletions core/types/arb_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func (tx *ArbitrumUnsignedTx) copy() TxData {
Nonce: tx.Nonce,
GasPrice: new(big.Int),
Gas: tx.Gas,
From: tx.From,
To: nil,
Value: new(big.Int),
Data: common.CopyBytes(tx.Data),
Expand Down Expand Up @@ -92,6 +93,7 @@ func (tx *ArbitrumContractTx) copy() TxData {
RequestId: tx.RequestId,
GasPrice: new(big.Int),
Gas: tx.Gas,
From: tx.From,
To: nil,
Value: new(big.Int),
Data: common.CopyBytes(tx.Data),
Expand Down
11 changes: 2 additions & 9 deletions core/types/receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,16 +339,9 @@ func (rs Receipts) EncodeIndex(i int, w *bytes.Buffer) {
switch r.Type {
case LegacyTxType:
rlp.Encode(w, data)
case AccessListTxType:
w.WriteByte(AccessListTxType)
rlp.Encode(w, data)
case DynamicFeeTxType:
w.WriteByte(DynamicFeeTxType)
rlp.Encode(w, data)
default:
// For unsupported types, write nothing. Since this is for
// DeriveSha, the error will be caught matching the derived hash
// to the block.
w.WriteByte(r.Type)
rlp.Encode(w, data)
}
}

Expand Down