2021-08-31 20:24:20 +00:00
|
|
|
package core
|
|
|
|
|
|
|
|
import (
|
2021-09-03 22:16:14 +00:00
|
|
|
"context"
|
|
|
|
"math/big"
|
2023-02-20 18:53:26 +00:00
|
|
|
"time"
|
2021-09-03 22:16:14 +00:00
|
|
|
|
|
|
|
"github.com/holiman/uint256"
|
2021-08-31 20:24:20 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Backend interface {
|
|
|
|
// General Ethereum API
|
|
|
|
Downloader() Downloader
|
|
|
|
SuggestGasTipCap(ctx context.Context) (*big.Int, error)
|
|
|
|
// ChainDb() Database
|
|
|
|
// AccountManager() *accounts.Manager
|
|
|
|
ExtRPCEnabled() bool
|
|
|
|
RPCGasCap() uint64 // global gas cap for eth_call over rpc: DoS protection
|
|
|
|
RPCTxFeeCap() float64 // global tx fee cap for all transaction related APIs
|
|
|
|
UnprotectedAllowed() bool // allows only for EIP155 transactions.
|
|
|
|
|
|
|
|
// Blockchain API
|
|
|
|
SetHead(number uint64)
|
|
|
|
HeaderByNumber(ctx context.Context, number int64) ([]byte, error) // RLP encoded header
|
|
|
|
HeaderByHash(ctx context.Context, hash Hash) ([]byte, error)
|
|
|
|
// HeaderByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*types.Header, error)
|
2021-09-03 22:16:14 +00:00
|
|
|
CurrentHeader() []byte // RLP encoded header
|
|
|
|
CurrentBlock() []byte // RLP encoded block
|
2021-08-31 20:24:20 +00:00
|
|
|
BlockByNumber(ctx context.Context, number int64) ([]byte, error) // RLP encoded block
|
2021-09-03 22:16:14 +00:00
|
|
|
BlockByHash(ctx context.Context, hash Hash) ([]byte, error) // RLP encoded block
|
2021-08-31 20:24:20 +00:00
|
|
|
// BlockByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*types.Block, error)
|
|
|
|
// StateAndHeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*state.StateDB, *types.Header, error)
|
|
|
|
// StateAndHeaderByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*state.StateDB, *types.Header, error)
|
|
|
|
GetReceipts(ctx context.Context, hash Hash) ([]byte, error) // JSON encoded receipt (YES, JSON)
|
|
|
|
GetTd(ctx context.Context, hash Hash) *big.Int
|
|
|
|
|
|
|
|
SubscribeChainEvent(ch chan<- ChainEvent) Subscription
|
|
|
|
SubscribeChainHeadEvent(ch chan<- ChainHeadEvent) Subscription
|
|
|
|
SubscribeChainSideEvent(ch chan<- ChainSideEvent) Subscription
|
|
|
|
|
|
|
|
// Transaction pool API
|
2021-09-03 22:16:14 +00:00
|
|
|
SendTx(ctx context.Context, signedTx []byte) error // RLP Encoded Transaction
|
2021-08-31 20:24:20 +00:00
|
|
|
GetTransaction(ctx context.Context, txHash Hash) ([]byte, Hash, uint64, uint64, error) // RLP Encoded transaction
|
2021-09-03 22:16:14 +00:00
|
|
|
GetPoolTransactions() ([][]byte, error) // []RLP ecnoded transactions
|
|
|
|
GetPoolTransaction(txHash Hash) []byte // RLP encoded transaction
|
2021-08-31 20:24:20 +00:00
|
|
|
GetPoolNonce(ctx context.Context, addr Address) (uint64, error)
|
|
|
|
Stats() (pending int, queued int)
|
|
|
|
TxPoolContent() (map[Address][][]byte, map[Address][][]byte) // RLP encoded transactions
|
|
|
|
SubscribeNewTxsEvent(chan<- NewTxsEvent) Subscription
|
|
|
|
|
|
|
|
// Filter API
|
|
|
|
BloomStatus() (uint64, uint64)
|
|
|
|
GetLogs(ctx context.Context, blockHash Hash) ([][]byte, error) // []RLP encoded logs
|
2021-09-03 22:16:14 +00:00
|
|
|
SubscribeLogsEvent(ch chan<- [][]byte) Subscription // []RLP encoded logs
|
|
|
|
SubscribePendingLogsEvent(ch chan<- [][]byte) Subscription // RLP Encoded logs
|
|
|
|
SubscribeRemovedLogsEvent(ch chan<- []byte) Subscription // RLP encoded logs
|
2021-08-31 20:24:20 +00:00
|
|
|
|
2023-04-07 21:28:23 +00:00
|
|
|
GetTrie(hash Hash) (Trie, error)
|
|
|
|
GetAccountTrie(stateRoot Hash, account Address) (Trie, error)
|
2023-06-22 07:20:28 +00:00
|
|
|
GetContractCode(Hash) ([]byte, error)
|
2023-04-07 21:28:23 +00:00
|
|
|
|
2021-08-31 20:24:20 +00:00
|
|
|
// ChainConfig() *params.ChainConfig
|
|
|
|
// Engine() consensus.Engine
|
|
|
|
}
|
|
|
|
|
|
|
|
type OpCode byte
|
|
|
|
|
2021-11-06 00:08:42 +00:00
|
|
|
type BlockTracer interface {
|
|
|
|
TracerResult
|
|
|
|
PreProcessBlock(hash Hash, number uint64, encoded []byte)
|
|
|
|
PreProcessTransaction(tx Hash, block Hash, i int)
|
|
|
|
BlockProcessingError(tx Hash, block Hash, err error)
|
|
|
|
PostProcessTransaction(tx Hash, block Hash, i int, receipt []byte)
|
|
|
|
PostProcessBlock(block Hash)
|
|
|
|
}
|
|
|
|
|
2023-02-20 18:53:26 +00:00
|
|
|
// The implementation of CaptureEnd below diverges from foundation Geth, we pass dummy variables in PluGeth
|
|
|
|
// in order to preserve the implementation of the tracing plugins in Plugeth-Plugins.
|
2021-08-31 20:24:20 +00:00
|
|
|
type TracerResult interface {
|
|
|
|
CaptureStart(from Address, to Address, create bool, input []byte, gas uint64, value *big.Int)
|
|
|
|
CaptureState(pc uint64, op OpCode, gas, cost uint64, scope ScopeContext, rData []byte, depth int, err error)
|
|
|
|
CaptureFault(pc uint64, op OpCode, gas, cost uint64, scope ScopeContext, depth int, err error)
|
2023-02-20 18:53:26 +00:00
|
|
|
CaptureEnd(output []byte, gasUsed uint64, t time.Duration, err error)
|
2021-11-06 00:08:42 +00:00
|
|
|
CaptureEnter(typ OpCode, from Address, to Address, input []byte, gas uint64, value *big.Int)
|
|
|
|
CaptureExit(output []byte, gasUsed uint64, err error)
|
2021-09-08 20:58:53 +00:00
|
|
|
Result() (interface{}, error)
|
|
|
|
}
|
|
|
|
|
2022-02-16 00:54:39 +00:00
|
|
|
type PreTracer interface {
|
|
|
|
CapturePreStart(from Address, to *Address, input []byte, gas uint64, value *big.Int)
|
|
|
|
}
|
|
|
|
|
2021-09-08 20:58:53 +00:00
|
|
|
type StateDB interface {
|
|
|
|
GetBalance(Address) *big.Int
|
|
|
|
|
|
|
|
GetNonce(Address) uint64
|
|
|
|
|
|
|
|
GetCodeHash(Address) Hash
|
|
|
|
GetCode(Address) []byte
|
|
|
|
GetCodeSize(Address) int
|
|
|
|
|
|
|
|
GetRefund() uint64
|
|
|
|
|
|
|
|
GetCommittedState(Address, Hash) Hash
|
|
|
|
GetState(Address, Hash) Hash
|
|
|
|
|
|
|
|
HasSuicided(Address) bool
|
|
|
|
|
|
|
|
// Exist reports whether the given account exists in state.
|
|
|
|
// Notably this should also return true for suicided accounts.
|
|
|
|
Exist(Address) bool
|
|
|
|
// Empty returns whether the given account is empty. Empty
|
|
|
|
// is defined according to EIP161 (balance = nonce = code = 0).
|
|
|
|
Empty(Address) bool
|
|
|
|
|
|
|
|
AddressInAccessList(addr Address) bool
|
|
|
|
SlotInAccessList(addr Address, slot Hash) (addressOk bool, slotOk bool)
|
2023-04-05 04:24:46 +00:00
|
|
|
|
|
|
|
IntermediateRoot(deleteEmptyObjects bool) Hash
|
2021-08-31 20:24:20 +00:00
|
|
|
}
|
|
|
|
|
2023-03-23 21:37:02 +00:00
|
|
|
type RWStateDB interface {
|
|
|
|
StateDB
|
2023-10-10 17:14:25 +00:00
|
|
|
AddBalance(add Address, amount *big.Int)
|
2023-03-23 21:37:02 +00:00
|
|
|
}
|
|
|
|
|
2021-08-31 20:24:20 +00:00
|
|
|
type ScopeContext interface {
|
2021-09-03 22:16:14 +00:00
|
|
|
Memory() Memory
|
|
|
|
Stack() Stack
|
2021-08-31 20:24:20 +00:00
|
|
|
Contract() Contract
|
|
|
|
}
|
|
|
|
|
|
|
|
type Memory interface {
|
2021-09-03 22:16:14 +00:00
|
|
|
GetCopy(int64, int64) []byte
|
|
|
|
Len() int
|
2021-08-31 20:24:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Stack interface {
|
2021-09-03 22:16:14 +00:00
|
|
|
Back(n int) *uint256.Int
|
|
|
|
Len() int
|
2021-08-31 20:24:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Contract interface {
|
2021-09-03 22:16:14 +00:00
|
|
|
AsDelegate() Contract
|
|
|
|
GetOp(n uint64) OpCode
|
|
|
|
GetByte(n uint64) byte
|
|
|
|
Caller() Address
|
|
|
|
Address() Address
|
|
|
|
Value() *big.Int
|
2022-01-14 21:25:37 +00:00
|
|
|
Input() []byte
|
|
|
|
Code() []byte
|
2021-08-31 20:24:20 +00:00
|
|
|
}
|
|
|
|
|
2021-09-03 22:16:14 +00:00
|
|
|
type Downloader interface {
|
|
|
|
Progress() Progress
|
2021-08-31 20:24:20 +00:00
|
|
|
}
|
|
|
|
|
2021-09-03 22:16:14 +00:00
|
|
|
type Progress interface {
|
|
|
|
StartingBlock() uint64
|
|
|
|
CurrentBlock() uint64
|
|
|
|
HighestBlock() uint64
|
|
|
|
PulledStates() uint64
|
|
|
|
KnownStates() uint64
|
2021-12-27 23:10:33 +00:00
|
|
|
SyncedAccounts() uint64
|
|
|
|
SyncedAccountBytes() uint64
|
|
|
|
SyncedBytecodes() uint64
|
|
|
|
SyncedBytecodeBytes() uint64
|
|
|
|
SyncedStorage() uint64
|
|
|
|
SyncedStorageBytes() uint64
|
|
|
|
HealedTrienodes() uint64
|
|
|
|
HealedTrienodeBytes() uint64
|
|
|
|
HealedBytecodes() uint64
|
|
|
|
HealedBytecodeBytes() uint64
|
|
|
|
HealingTrienodes() uint64
|
|
|
|
HealingBytecode() uint64
|
2021-08-31 20:24:20 +00:00
|
|
|
}
|
|
|
|
|
2021-09-03 22:16:14 +00:00
|
|
|
type Node interface {
|
|
|
|
Server() Server
|
|
|
|
DataDir() string
|
|
|
|
InstanceDir() string
|
|
|
|
IPCEndpoint() string
|
|
|
|
HTTPEndpoint() string
|
|
|
|
WSEndpoint() string
|
|
|
|
ResolvePath(x string) string
|
2021-10-08 18:46:44 +00:00
|
|
|
Attach() (Client, error)
|
2022-05-16 15:56:49 +00:00
|
|
|
Close() error
|
2021-10-08 18:46:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Client interface {
|
|
|
|
Call(interface{}, string, ...interface{}) error
|
2021-08-31 20:24:20 +00:00
|
|
|
}
|
|
|
|
|
2021-09-03 22:16:14 +00:00
|
|
|
type Server interface {
|
|
|
|
PeerCount() int
|
2021-08-31 20:24:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Logger interface {
|
2021-09-03 22:16:14 +00:00
|
|
|
Trace(string, ...interface{})
|
|
|
|
Debug(string, ...interface{})
|
|
|
|
Info(string, ...interface{})
|
|
|
|
Warn(string, ...interface{})
|
|
|
|
Crit(string, ...interface{})
|
|
|
|
Error(string, ...interface{})
|
2021-08-31 20:24:20 +00:00
|
|
|
}
|
2021-08-31 20:40:39 +00:00
|
|
|
|
2021-09-03 22:16:14 +00:00
|
|
|
type PluginLoader interface {
|
|
|
|
Lookup(name string, validate func(interface{}) bool) []interface{}
|
2021-09-16 20:52:50 +00:00
|
|
|
GetFeed() Feed
|
|
|
|
}
|
|
|
|
|
|
|
|
type Subscription interface {
|
|
|
|
Err() <-chan error // returns the error channel
|
|
|
|
Unsubscribe() // cancels sending of events, closing the error channel
|
|
|
|
}
|
|
|
|
|
|
|
|
type Feed interface {
|
|
|
|
Send(interface{}) int
|
|
|
|
Subscribe(channel interface{}) Subscription
|
2021-08-31 20:40:39 +00:00
|
|
|
}
|
2022-02-03 04:48:25 +00:00
|
|
|
|
|
|
|
type BlockContext struct {
|
|
|
|
Coinbase Address
|
|
|
|
GasLimit uint64
|
|
|
|
BlockNumber *big.Int
|
2023-02-20 20:09:44 +00:00
|
|
|
Time *big.Int
|
2022-02-03 04:48:25 +00:00
|
|
|
Difficulty *big.Int
|
|
|
|
BaseFee *big.Int
|
|
|
|
}
|
2022-12-08 01:59:37 +00:00
|
|
|
|
|
|
|
type Context interface {
|
|
|
|
Set(string, string) error
|
|
|
|
String(string) string
|
|
|
|
Bool(string) bool
|
|
|
|
}
|
2023-04-07 17:48:42 +00:00
|
|
|
|
|
|
|
type Trie interface {
|
|
|
|
GetKey([]byte) []byte
|
2023-05-05 21:04:28 +00:00
|
|
|
GetAccount(address Address) (*StateAccount, error)
|
2023-04-07 17:48:42 +00:00
|
|
|
Hash() Hash
|
|
|
|
NodeIterator(startKey []byte) NodeIterator
|
|
|
|
Prove(key []byte, fromLevel uint, proofDb KeyValueWriter) error
|
|
|
|
}
|
|
|
|
|
|
|
|
type StateAccount struct {
|
|
|
|
Nonce uint64
|
|
|
|
Balance *big.Int
|
|
|
|
Root Hash // merkle root of the storage trie
|
|
|
|
CodeHash []byte
|
|
|
|
}
|
|
|
|
|
|
|
|
type NodeIterator interface {
|
|
|
|
Next(bool) bool
|
|
|
|
Error() error
|
|
|
|
Hash() Hash
|
|
|
|
Parent() Hash
|
|
|
|
Path() []byte
|
|
|
|
NodeBlob() []byte
|
|
|
|
Leaf() bool
|
|
|
|
LeafKey() []byte
|
|
|
|
LeafBlob() []byte
|
|
|
|
LeafProof() [][]byte
|
|
|
|
AddResolver(NodeResolver)
|
|
|
|
}
|
|
|
|
|
|
|
|
type NodeResolver func(owner Hash, path []byte, hash Hash) []byte
|
|
|
|
|
|
|
|
type KeyValueWriter interface {
|
|
|
|
Put(key []byte, value []byte) error
|
|
|
|
Delete(key []byte) error
|
2023-05-05 21:04:28 +00:00
|
|
|
}
|