Documentation
¶
Index ¶
- func ValidateWitnessPreState(witness *Witness, headerReader HeaderReader) error
- type BorWitness
- type CodeRoutingBatch
- type CodeRoutingDB
- func (db *CodeRoutingDB) Delete(key []byte) error
- func (db *CodeRoutingDB) Get(key []byte) ([]byte, error)
- func (db *CodeRoutingDB) Has(key []byte) (bool, error)
- func (db *CodeRoutingDB) NewBatch() ethdb.Batch
- func (db *CodeRoutingDB) NewBatchWithSize(size int) ethdb.Batch
- func (db *CodeRoutingDB) Put(key []byte, value []byte) error
- type ExtWitness
- type HeaderReader
- type MockHeaderReader
- type Witness
- func (w *Witness) AddBlockHash(number uint64)
- func (w *Witness) AddCode(code []byte)
- func (w *Witness) AddKey()
- func (w *Witness) AddState(nodes map[string][]byte)
- func (w *Witness) Copy() *Witness
- func (w *Witness) DecodeRLP(s *rlp.Stream) error
- func (w *Witness) EncodeRLP(wr io.Writer) error
- func (w *Witness) Header() *types.Header
- func (w *Witness) HeaderReader() HeaderReader
- func (w *Witness) MakeHashDB(diskdb ethdb.Database) ethdb.Database
- func (w *Witness) Root() common.Hash
- func (w *Witness) SetHeader(header *types.Header)
- func (w *Witness) ToExtWitness() *ExtWitness
- type WitnessStats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ValidateWitnessPreState ¶
func ValidateWitnessPreState(witness *Witness, headerReader HeaderReader) error
ValidateWitnessPreState validates that the witness pre-state root matches the parent block's state root.
Types ¶
type BorWitness ¶
BorWitness is the canonical 3-field RLP encoding used for network transmission in Bor. The State field carries all proof data — both contract bytecodes and MPT state trie nodes — as a flat list of byte slices.
type CodeRoutingBatch ¶
CodeRoutingBatch is a batch that routes code writes to the diskdb
func (*CodeRoutingBatch) Delete ¶
func (b *CodeRoutingBatch) Delete(key []byte) error
type CodeRoutingDB ¶
CodeRoutingDB is a database that routes code reads/writes to the diskdb.
func NewCodeRoutingDB ¶
func NewCodeRoutingDB(diskdb ethdb.Database) *CodeRoutingDB
func (*CodeRoutingDB) Delete ¶
func (db *CodeRoutingDB) Delete(key []byte) error
func (*CodeRoutingDB) NewBatch ¶
func (db *CodeRoutingDB) NewBatch() ethdb.Batch
func (*CodeRoutingDB) NewBatchWithSize ¶
func (db *CodeRoutingDB) NewBatchWithSize(size int) ethdb.Batch
type ExtWitness ¶
type ExtWitness struct {
Context *types.Header
Headers []*types.Header `json:"headers"`
Codes []hexutil.Bytes `json:"codes"`
State []hexutil.Bytes `json:"state"`
Keys []hexutil.Bytes `json:"keys"`
}
ExtWitness is a witness representation used by the JSON debug API and for backward-compatible RLP decoding of peers that temporarily used the extended 5-field format. It is not the canonical wire format.
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 MockHeaderReader ¶
type MockHeaderReader struct {
// contains filtered or unexported fields
}
MockHeaderReader is a mock implementation of HeaderReader for testing.
func NewMockHeaderReader ¶
func NewMockHeaderReader() *MockHeaderReader
func (*MockHeaderReader) AddHeader ¶
func (m *MockHeaderReader) AddHeader(header *types.Header)
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 GetWitnessFromRlp ¶
GetWitnessFromRlp decodes a witness from its RLP encoded form.
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) DecodeRLP ¶
DecodeRLP decodes a witness from RLP. It first attempts the canonical BorWitness 3-field format. If that fails (e.g. the peer sent the legacy 5-field ExtWitness encoding), it falls back to ExtWitness for backward compatibility.
When decoding BorWitness, State items are placed into w.State and w.Codes is left empty, since codes are not part of the BorWitness wire format.
func (*Witness) EncodeRLP ¶
EncodeRLP serializes a witness as RLP using the canonical BorWitness 3-field format. Only state trie nodes are encoded; contract bytecodes are not included in the wire format.
func (*Witness) HeaderReader ¶
func (w *Witness) HeaderReader() HeaderReader
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) ToExtWitness ¶
func (w *Witness) ToExtWitness() *ExtWitness
ToExtWitness converts our internal witness representation to the ExtWitness form used by the JSON debug API.
type WitnessStats ¶
type WitnessStats struct {
// contains filtered or unexported fields
}
WitnessStats aggregates statistics for account and storage trie accesses.
func NewWitnessStats ¶
func NewWitnessStats() *WitnessStats
NewWitnessStats creates a new WitnessStats collector.
func (*WitnessStats) Add ¶
func (s *WitnessStats) Add(nodes map[string][]byte, owner common.Hash)
Add records trie access depths from the given node paths. If `owner` is the zero hash, accesses are attributed to the account trie; otherwise, they are attributed to the storage trie of that account.
func (*WitnessStats) ReportMetrics ¶
func (s *WitnessStats) ReportMetrics(blockNumber uint64)
ReportMetrics reports the collected statistics to the global metrics registry.