-
Notifications
You must be signed in to change notification settings - Fork 270
Expand file tree
/
Copy pathexecution.go
More file actions
121 lines (114 loc) · 5.02 KB
/
Copy pathexecution.go
File metadata and controls
121 lines (114 loc) · 5.02 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package execution
import (
"context"
"time"
)
// Executor defines the interface that execution clients must implement to be compatible with Evolve.
// This interface enables the separation between consensus and execution layers, allowing for modular
// and pluggable execution environments.
//
// Note: if you are modifying this interface, ensure that all implementations are compatible (evm, abci, protobuf/grpc, etc..
type Executor interface {
// InitChain initializes a new blockchain instance with genesis parameters.
// Requirements:
// - Must generate initial state root representing empty/genesis state
// - Must validate and store genesis parameters for future reference
// - Must ensure idempotency (repeated calls with identical parameters should return same results)
// - Must return error if genesis parameters are invalid
// - Must return maxBytes indicating maximum allowed bytes for a set of transactions in a block
//
// Parameters:
// - ctx: Context for timeout/cancellation control
// - genesisTime: timestamp marking chain start time in UTC
// - initialHeight: First block height (must be > 0)
// - chainID: Unique identifier string for the blockchain
//
// Returns:
// - stateRoot: Hash representing initial state
// - maxBytes: Maximum allowed bytes for transactions in a block
// - err: Any initialization errors
InitChain(ctx context.Context, genesisTime time.Time, initialHeight uint64, chainID string) (stateRoot []byte, maxBytes uint64, err error)
// GetTxs fetches available transactions from the execution layer's mempool.
// Requirements:
// - Must return currently valid transactions only
// - Must handle empty mempool case gracefully
// - Must respect context cancellation/timeout
// - Should perform basic transaction validation
// - Should not remove transactions from mempool
// - May remove invalid transactions from mempool
//
// Parameters:
// - ctx: Context for timeout/cancellation control
//
// Returns:
// - []types.Tx: Slice of valid transactions
// - error: Any errors during transaction retrieval
GetTxs(ctx context.Context) ([][]byte, error)
// ExecuteTxs processes transactions to produce a new block state.
// Requirements:
// - Must validate state transition against previous state root
// - Must handle empty transaction list
// - Must handle gracefully gibberish transactions
// - Must maintain deterministic execution
// - Must respect context cancellation/timeout
// - The rest of the rules are defined by the specific execution layer
//
// Parameters:
// - ctx: Context for timeout/cancellation control
// - txs: Ordered list of transactions to execute
// - blockHeight: Height of block being created (must be > 0)
// - timestamp: Block creation time in UTC
// - prevStateRoot: Previous block's state root hash
//
// Returns:
// - updatedStateRoot: New state root after executing transactions
// - maxBytes: Maximum allowed transaction size (may change with protocol updates)
// - err: Any execution errors
ExecuteTxs(ctx context.Context, txs [][]byte, blockHeight uint64, timestamp time.Time, prevStateRoot []byte) (updatedStateRoot []byte, maxBytes uint64, err error)
// SetFinal marks a block as finalized at the specified height.
// Requirements:
// - Must verify block exists at specified height
// - Must be idempotent
// - Must maintain finality guarantees (no reverting finalized blocks)
// - Must respect context cancellation/timeout
// - Should clean up any temporary state/resources
//
// Parameters:
// - ctx: Context for timeout/cancellation control
// - blockHeight: Height of block to finalize
//
// Returns:
// - error: Any errors during finalization
SetFinal(ctx context.Context, blockHeight uint64) error
}
// HeightProvider is an optional interface that execution clients can implement
// to support height synchronization checks between ev-node and the execution layer.
type HeightProvider interface {
// GetLatestHeight returns the current block height of the execution layer.
// This is useful for detecting desynchronization between ev-node and the execution layer
// after crashes or restarts.
//
// Parameters:
// - ctx: Context for timeout/cancellation control
//
// Returns:
// - height: Current block height of the execution layer
// - error: Any errors during height retrieval
GetLatestHeight(ctx context.Context) (uint64, error)
}
// Rollbackable is an optional interface that execution clients can implement
// to support automatic rollback when the execution layer is ahead of the target height.
// This enables automatic recovery during rolling restarts when the EL has committed
// blocks that were not replicated to Raft.
type Rollbackable interface {
// Rollback resets the execution layer head to the specified height.
// This is used for recovery when the EL is ahead of the consensus layer.
//
// Parameters:
// - ctx: Context for timeout/cancellation control
// - targetHeight: Height to rollback to (must be <= current height)
//
// Returns:
// - error: Any errors during rollback
Rollback(ctx context.Context, targetHeight uint64) error
}