Documentation
¶
Index ¶
- type ExecutionWitness
- type HeaderReader
- type Witness
- func (w *Witness) AddBlockHash(number uint64)
- func (w *Witness) AddCode(code []byte)
- func (w *Witness) AddState(nodes map[string]struct{})
- func (w *Witness) Copy() *Witness
- func (w *Witness) DecodeRLP(s *rlp.Stream) error
- func (w *Witness) EncodeRLP(wr io.Writer) error
- func (w *Witness) MakeHashDB() ethdb.Database
- func (w *Witness) Root() common.Hash
- func (w *Witness) ToExecutionWitness() *ExecutionWitness
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ExecutionWitness ¶
type ExecutionWitness struct { Headers []*types.Header `json:"headers"` Codes map[string]string `json:"codes"` State map[string]string `json:"state"` }
ExecutionWitness is a witness json encoding for transferring across clients in the future, we'll probably consider using the extWitness format instead for less overhead. currently we're using this format for compatibility with reth and also for simplicity in terms of parsing.
type HeaderReader ¶
type HeaderReader interface { // GetHeader retrieves a block header from the database by hash and number, GetHeader(hash common.Hash, number uint64) *types.Header }
HeaderReader is an interface to pull in headers in place of block hashes for the witness.
type Witness ¶
type Witness struct { Headers []*types.Header // Past headers in reverse order (0=parent, 1=parent's-parent, etc). First *must* be set. Codes map[string]struct{} // Set of bytecodes ran or accessed State map[string]struct{} // Set of MPT state trie nodes (account and storage together) // contains filtered or unexported fields }
Witness encompasses the state required to apply a set of transactions and derive a post state/receipt root.
func NewWitness ¶
func NewWitness(context *types.Header, chain HeaderReader) (*Witness, error)
NewWitness creates an empty witness ready for population.
func (*Witness) AddBlockHash ¶
AddBlockHash adds a "blockhash" to the witness with the designated offset from chain head. Under the hood, this method actually pulls in enough headers from the chain to cover the block being added.
func (*Witness) Copy ¶
Copy deep-copies the witness object. Witness.Block isn't deep-copied as it is never mutated by Witness
func (*Witness) MakeHashDB ¶
MakeHashDB imports tries, codes and block hashes from a witness into a new hash-based memory db. We could eventually rewrite this into a pathdb, but simple is better for now.
Note, this hashdb approach is quite strictly self-validating:
- Headers are persisted keyed by hash, so blockhash will error on junk
- Codes are persisted keyed by hash, so bytecode lookup will error on junk
- Trie nodes are persisted keyed by hash, so trie expansion will error on junk
Acceleration structures built would need to explicitly validate the witness.
func (*Witness) Root ¶
Root returns the pre-state root from the first header.
Note, this method will panic in case of a bad witness (but RLP decoding will sanitize it and fail before that).
func (*Witness) ToExecutionWitness ¶
func (w *Witness) ToExecutionWitness() *ExecutionWitness
ToExecutionWitness converts a witness to an execution witness format that is compatible with reth. keccak(node) => node keccak(bytecodes) => bytecodes