forked from OffchainLabs/nitro
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathengine.go
88 lines (70 loc) · 2.47 KB
/
engine.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright 2021-2022, Offchain Labs, Inc.
// For license information, see https://github.com/nitro/blob/master/LICENSE
package arbos
import (
"errors"
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/rpc"
"github.com/ethereum/go-ethereum/trie"
)
type Engine struct {
IsSequencer bool
}
func (e Engine) Author(header *types.Header) (common.Address, error) {
return header.Coinbase, nil
}
func (e Engine) VerifyHeader(chain consensus.ChainHeaderReader, header *types.Header) error {
// TODO what verification should be done here?
return nil
}
func (e Engine) VerifyHeaders(chain consensus.ChainHeaderReader, headers []*types.Header) (chan<- struct{}, <-chan error) {
errors := make(chan error, len(headers))
for i := range headers {
errors <- e.VerifyHeader(chain, headers[i])
}
return make(chan struct{}), errors
}
func (e Engine) VerifyUncles(chain consensus.ChainReader, block *types.Block) error {
if len(block.Uncles()) != 0 {
return errors.New("uncles not supported")
}
return nil
}
func (e Engine) Prepare(chain consensus.ChainHeaderReader, header *types.Header) error {
header.Difficulty = big.NewInt(1)
return nil
}
func (e Engine) Finalize(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, body *types.Body) {
FinalizeBlock(header, body.Transactions, state, chain.Config())
}
func (e Engine) FinalizeAndAssemble(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, body *types.Body, receipts []*types.Receipt) (*types.Block, error) {
e.Finalize(chain, header, state, body)
block := types.NewBlock(header, &types.Body{Transactions: body.Transactions}, receipts, trie.NewStackTrie(nil))
return block, nil
}
func (e Engine) Seal(chain consensus.ChainHeaderReader, block *types.Block, results chan<- *types.Block, stop <-chan struct{}) error {
if !e.IsSequencer {
return errors.New("sealing not supported")
}
if len(block.Transactions()) == 0 {
return nil
}
results <- block
return nil
}
func (e Engine) SealHash(header *types.Header) common.Hash {
return header.Hash()
}
func (e Engine) CalcDifficulty(chain consensus.ChainHeaderReader, time uint64, parent *types.Header) *big.Int {
return big.NewInt(1)
}
func (e Engine) APIs(chain consensus.ChainHeaderReader) []rpc.API {
return nil
}
func (e Engine) Close() error {
return nil
}