fix some things that broke in the latest rebase. fix the cross-validator

This commit is contained in:
Jared Wasinger 2024-02-13 21:27:50 -08:00
parent 1329dcf6fb
commit ad291040a3
9 changed files with 36 additions and 25 deletions

View file

@ -81,7 +81,7 @@ var (
Usage: "",
ArgsUsage: "server --chain-config /path/to/chain-config.json",
Flags: []cli.Flag{ChainConfigFlag},
Description: `Runs an HTTP server which provides an API endpoint for stateless block verification`,
Description: `Runs an HTTP server (temporarily hard-coded to listen on the local address at port 8080) which provides an API endpoint for stateless block verification`,
}
)

View file

@ -2,6 +2,7 @@ package main
import (
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/params"
"github.com/urfave/cli/v2"
"os"
"os/signal"
@ -9,7 +10,14 @@ import (
)
func server(ctx *cli.Context) error {
chainConfig := loadChainConfig(ctx.String(ChainConfigFlag.Name))
var chainConfig *params.ChainConfig
if chainConfigFlagVal := ctx.String(ChainConfigFlag.Name); chainConfigFlagVal != "" {
chainConfig = loadChainConfig(ctx.String(ChainConfigFlag.Name))
} else {
// TODO: instead of assuming mainnet configuration in absence of chain config
// val, accept known chain configurations via network preset flag.
chainConfig = params.MainnetChainConfig
}
closeCh, _, err := utils.RunLocalServer(chainConfig, 8080)
if err != nil {
return err

View file

@ -12,7 +12,7 @@ import (
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/trie"
"github.com/ethereum/go-ethereum/triedb"
"io"
"net"
"net/http"
@ -25,7 +25,7 @@ func StatelessExecute(logOutput io.Writer, chainCfg *params.ChainConfig, witness
}
_, prestateRoot := rawdb.ReadAccountTrieNode(rawDb, nil)
db, err := state.New(prestateRoot, state.NewDatabaseWithConfig(rawDb, trie.PathDefaults), nil)
db, err := state.New(prestateRoot, state.NewDatabaseWithConfig(rawDb, triedb.PathDefaults), nil)
if err != nil {
return common.Hash{}, err
}
@ -49,8 +49,9 @@ func StatelessExecute(logOutput io.Writer, chainCfg *params.ChainConfig, witness
return root, nil
}
// RunLocalServer runs an http server at the specified port (or 0 to use a random port).
// The server provides a POST endpoint /verify_block which takes input as an RLP-encoded
// RunLocalServer runs an http server on the local address at the specified
// port (or 0 to use a random port).
// The server provides a POST endpoint /verify_block which takes input as an octet-stream RLP-encoded
// block witness proof in the body, executes the block proof and returns the computed state root.
func RunLocalServer(chainConfig *params.ChainConfig, port int) (closeChan chan<- struct{}, actualPort int, err error) {
mux := http.NewServeMux()

View file

@ -30,7 +30,6 @@ import (
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rpc"
"github.com/ethereum/go-ethereum/trie"
"github.com/holiman/uint256"
)
// Proof-of-stake protocol constants.

View file

@ -268,7 +268,7 @@ type BlockChain struct {
// remote endpoint. If validation fails, they are dumped to the folder specified at witnessRecordingPath
func NewBlockchainWithCrossValidator(endpoint string, witnessRecordingPath string, db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis, overrides *ChainOverrides, engine consensus.Engine, vmConfig vm.Config, shouldPreserve func(header *types.Header) bool, txLookupLimit *uint64) (*BlockChain, error) {
bc, err := NewBlockChain(db, cacheConfig, genesis, overrides, engine, vmConfig, shouldPreserve, txLookupLimit)
bc.crossValidator = &crossValidator{witnessRecordingPath, endpoint}
bc.crossValidator = &crossValidator{endpoint, witnessRecordingPath}
return bc, err
}

View file

@ -1255,8 +1255,8 @@ func (s *StateDB) Witness() *Witness {
func (s *StateDB) ApplyWithdrawals(withdrawals types.Withdrawals) {
for _, w := range withdrawals {
// Convert amount from gwei to wei.
amount := new(big.Int).SetUint64(w.Amount)
amount = amount.Mul(amount, big.NewInt(params.GWei))
amount := new(uint256.Int).SetUint64(w.Amount)
amount = amount.Mul(amount, uint256.NewInt(params.GWei))
s.AddBalance(w.Address, amount)
}

View file

@ -163,19 +163,19 @@ func TestExecutionSpec(t *testing.T) {
}
func execBlockTest(t *testing.T, bt *testMatcher, test *BlockTest) {
if err := bt.checkFailure(t, test.Run(false, rawdb.HashScheme, nil)); err != nil {
if err := bt.checkFailure(t, test.Run(false, rawdb.HashScheme, nil, nil)); err != nil {
t.Errorf("test in hash mode without snapshotter failed: %v", err)
return
}
if err := bt.checkFailure(t, test.Run(true, rawdb.HashScheme, nil)); err != nil {
if err := bt.checkFailure(t, test.Run(true, rawdb.HashScheme, nil, nil)); err != nil {
t.Errorf("test in hash mode with snapshotter failed: %v", err)
return
}
if err := bt.checkFailure(t, test.Run(false, rawdb.PathScheme, nil)); err != nil {
if err := bt.checkFailure(t, test.Run(false, rawdb.PathScheme, nil, nil)); err != nil {
t.Errorf("test in path mode without snapshotter failed: %v", err)
return
}
if err := bt.checkFailure(t, test.Run(true, rawdb.PathScheme, nil)); err != nil {
if err := bt.checkFailure(t, test.Run(true, rawdb.PathScheme, nil, nil)); err != nil {
t.Errorf("test in path mode with snapshotter failed: %v", err)
return
}

View file

@ -112,15 +112,15 @@ type btHeaderMarshaling struct {
ExcessBlobGas *math.HexOrDecimal64
}
func (t *BlockTest) Run(snapshotter bool, scheme string, tracer vm.EVMLogger) error {
return t.run(false, snapshotter, scheme, tracer)
func (t *BlockTest) Run(snapshotter bool, scheme string, tracer vm.EVMLogger, postCheck func(error, *core.BlockChain)) error {
return t.run(false, snapshotter, scheme, tracer, postCheck)
}
func (t *BlockTest) RunStateless(snapshotter bool, scheme string, tracer vm.EVMLogger) error {
return t.run(true, snapshotter, scheme, tracer)
func (t *BlockTest) RunStateless(snapshotter bool, scheme string, tracer vm.EVMLogger, postCheck func(error, *core.BlockChain)) error {
return t.run(true, snapshotter, scheme, tracer, postCheck)
}
func (t *BlockTest) run(stateless bool, snapshotter bool, scheme string, tracer vm.EVMLogger) error {
func (t *BlockTest) run(stateless bool, snapshotter bool, scheme string, tracer vm.EVMLogger, postCheck func(error, *core.BlockChain)) (result error) {
config, ok := Forks[t.json.Network]
if !ok {
return UnsupportedForkError{t.json.Network}
@ -191,6 +191,11 @@ func (t *BlockTest) run(stateless bool, snapshotter bool, scheme string, tracer
if err != nil {
return err
}
// Import succeeded: regardless of whether the _test_ succeeds or not, schedule
// the post-check to run
if postCheck != nil {
defer postCheck(result, chain)
}
cmlast := chain.CurrentBlock().Hash()
if common.Hash(t.json.BestBlock) != cmlast {
return fmt.Errorf("last block hash validation mismatch: want: %x, have: %x", t.json.BestBlock, cmlast)

View file

@ -220,13 +220,11 @@ func (t *StateTrie) AccessList() map[string][]byte {
func (t *StateTrie) CommitAndObtainAccessList(collectLeaf bool) (common.Hash, *trienode.NodeSet, map[string][]byte, error) {
// Write all the pre-images to the actual disk database
if len(t.getSecKeyCache()) > 0 {
if t.preimages != nil {
preimages := make(map[common.Hash][]byte)
for hk, key := range t.secKeyCache {
preimages[common.BytesToHash([]byte(hk))] = key
}
t.preimages.insertPreimage(preimages)
preimages := make(map[common.Hash][]byte)
for hk, key := range t.secKeyCache {
preimages[common.BytesToHash([]byte(hk))] = key
}
t.db.InsertPreimage(preimages)
t.secKeyCache = make(map[string][]byte)
}
// Commit the trie and return its modified nodeset.