2023-07-14 14:38:17 +00:00
|
|
|
package eth1
|
|
|
|
|
|
|
|
import (
|
2023-07-15 16:31:15 +00:00
|
|
|
"context"
|
|
|
|
|
|
|
|
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
2023-07-14 14:38:17 +00:00
|
|
|
"github.com/ledgerwatch/erigon-lib/gointerfaces/execution"
|
|
|
|
|
|
|
|
"github.com/ledgerwatch/erigon-lib/kv"
|
2023-07-15 16:31:15 +00:00
|
|
|
"github.com/ledgerwatch/erigon/core/rawdb"
|
|
|
|
"github.com/ledgerwatch/erigon/core/types"
|
2023-07-14 14:38:17 +00:00
|
|
|
"github.com/ledgerwatch/erigon/turbo/services"
|
|
|
|
)
|
|
|
|
|
|
|
|
// EthereumExecutionModule describes ethereum execution logic and indexing.
|
|
|
|
type EthereumExecutionModule struct {
|
|
|
|
// Snapshots + MDBX
|
|
|
|
blockReader services.FullBlockReader
|
|
|
|
|
|
|
|
// MDBX database
|
2023-07-15 16:31:15 +00:00
|
|
|
db kv.RwDB // main database
|
|
|
|
chainDb kv.RwDB // this is a database used to queue insert headers/bodies requests
|
2023-07-14 14:38:17 +00:00
|
|
|
|
|
|
|
execution.UnimplementedExecutionServer
|
|
|
|
}
|
|
|
|
|
2023-07-15 16:31:15 +00:00
|
|
|
func NewEthereumExecutionModule(blockReader services.FullBlockReader, db, chainDb kv.RwDB) *EthereumExecutionModule {
|
|
|
|
return &EthereumExecutionModule{
|
|
|
|
blockReader: blockReader,
|
|
|
|
db: db,
|
|
|
|
chainDb: chainDb,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *EthereumExecutionModule) getHeader(ctx context.Context, tx, tx2 kv.Tx, blockHash libcommon.Hash, blockNumber uint64) (*types.Header, error) {
|
|
|
|
header := rawdb.ReadHeader(tx, blockHash, blockNumber)
|
|
|
|
if header != nil {
|
|
|
|
return header, nil
|
|
|
|
}
|
|
|
|
if e.blockReader == nil {
|
|
|
|
return rawdb.ReadHeader(tx2, blockHash, blockNumber), nil
|
|
|
|
}
|
|
|
|
return e.blockReader.Header(ctx, tx2, blockHash, blockNumber)
|
|
|
|
}
|
2023-07-14 14:38:17 +00:00
|
|
|
|
2023-07-15 16:31:15 +00:00
|
|
|
func (e *EthereumExecutionModule) getBody(ctx context.Context, tx, tx2 kv.Tx, blockHash libcommon.Hash, blockNumber uint64) (*types.Body, error) {
|
|
|
|
body, _, _ := rawdb.ReadBody(tx, blockHash, blockNumber)
|
|
|
|
if body != nil {
|
|
|
|
return body, nil
|
|
|
|
}
|
|
|
|
if e.blockReader == nil {
|
|
|
|
body, _, _ := rawdb.ReadBody(tx2, blockHash, blockNumber)
|
|
|
|
return body, nil
|
|
|
|
}
|
|
|
|
return e.blockReader.BodyWithTransactions(ctx, tx2, blockHash, blockNumber)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *EthereumExecutionModule) canonicalHash(ctx context.Context, tx kv.Tx, blockNumber uint64) (libcommon.Hash, error) {
|
|
|
|
if e.blockReader == nil {
|
|
|
|
return rawdb.ReadCanonicalHash(tx, blockNumber)
|
|
|
|
}
|
|
|
|
return e.blockReader.CanonicalHash(ctx, tx, blockNumber)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remaining
|
2023-07-14 14:38:17 +00:00
|
|
|
|
|
|
|
// func (execution.UnimplementedExecutionServer).AssembleBlock(context.Context, *execution.EmptyMessage) (*types.ExecutionPayload, error)
|
|
|
|
// func (execution.UnimplementedExecutionServer).UpdateForkChoice(context.Context, *types.H256) (*execution.ForkChoiceReceipt, error)
|
|
|
|
// func (execution.UnimplementedExecutionServer).ValidateChain(context.Context, *types.H256) (*execution.ValidationReceipt, error)
|