erigon-pulse/ethdb/privateapi/engine_test.go

258 lines
8.5 KiB
Go
Raw Normal View History

2021-11-26 11:59:05 +01:00
package privateapi
import (
"context"
"testing"
"github.com/ledgerwatch/erigon-lib/chain"
libcommon "github.com/ledgerwatch/erigon-lib/common"
2021-11-26 11:59:05 +01:00
"github.com/ledgerwatch/erigon-lib/gointerfaces"
"github.com/ledgerwatch/erigon-lib/gointerfaces/remote"
types2 "github.com/ledgerwatch/erigon-lib/gointerfaces/types"
2021-11-27 16:29:46 +01:00
"github.com/ledgerwatch/erigon-lib/kv"
2021-11-26 11:59:05 +01:00
"github.com/ledgerwatch/erigon-lib/kv/memdb"
"github.com/stretchr/testify/require"
2021-11-26 11:59:05 +01:00
"github.com/ledgerwatch/erigon/core/rawdb"
"github.com/ledgerwatch/erigon/turbo/engineapi"
"github.com/ledgerwatch/erigon/turbo/shards"
"github.com/ledgerwatch/erigon/turbo/stages/headerdownload"
2021-11-26 11:59:05 +01:00
)
2021-11-26 14:51:32 +01:00
// Hashes
var (
startingHeadHash = libcommon.HexToHash("0x1")
payload1Hash = libcommon.HexToHash("2afc6f4132be8d1fded51aa7f914fd831d2939a100f61322842ab41d7898255b")
payload2Hash = libcommon.HexToHash("219bb787708f832e40b734ab925e67e33f91f2c2a2a01b8f5f5f6284410982a6")
payload3Hash = libcommon.HexToHash("a2dd4fc599747c1ce2176a4abae13afbc7ccb4a240f8f4cf22252767bab52f12")
2021-11-26 14:51:32 +01:00
)
// Payloads
var (
2022-08-10 19:04:13 +07:00
mockPayload1 = &types2.ExecutionPayload{
ParentHash: gointerfaces.ConvertHashToH256(libcommon.HexToHash("0x2")),
2021-11-26 14:51:32 +01:00
BlockHash: gointerfaces.ConvertHashToH256(payload1Hash),
ReceiptRoot: gointerfaces.ConvertHashToH256(libcommon.HexToHash("0x3")),
StateRoot: gointerfaces.ConvertHashToH256(libcommon.HexToHash("0x4")),
PrevRandao: gointerfaces.ConvertHashToH256(libcommon.HexToHash("0x0b3")),
2021-11-26 14:51:32 +01:00
LogsBloom: gointerfaces.ConvertBytesToH2048(make([]byte, 256)),
ExtraData: make([]byte, 0),
BaseFeePerGas: gointerfaces.ConvertHashToH256(libcommon.HexToHash("0x0b3")),
2021-11-26 14:51:32 +01:00
BlockNumber: 100,
GasLimit: 52,
GasUsed: 4,
Timestamp: 4,
Coinbase: gointerfaces.ConvertAddressToH160(libcommon.HexToAddress("0x1")),
2021-11-26 14:51:32 +01:00
Transactions: make([][]byte, 0),
}
2022-08-10 19:04:13 +07:00
mockPayload2 = &types2.ExecutionPayload{
2021-11-26 14:51:32 +01:00
ParentHash: gointerfaces.ConvertHashToH256(payload1Hash),
BlockHash: gointerfaces.ConvertHashToH256(payload2Hash),
ReceiptRoot: gointerfaces.ConvertHashToH256(libcommon.HexToHash("0x3")),
StateRoot: gointerfaces.ConvertHashToH256(libcommon.HexToHash("0x4")),
PrevRandao: gointerfaces.ConvertHashToH256(libcommon.HexToHash("0x0b3")),
2021-11-26 14:51:32 +01:00
LogsBloom: gointerfaces.ConvertBytesToH2048(make([]byte, 256)),
ExtraData: make([]byte, 0),
BaseFeePerGas: gointerfaces.ConvertHashToH256(libcommon.HexToHash("0x0b3")),
2021-11-26 14:51:32 +01:00
BlockNumber: 101,
GasLimit: 52,
GasUsed: 4,
Timestamp: 4,
Coinbase: gointerfaces.ConvertAddressToH160(libcommon.HexToAddress("0x1")),
2021-11-26 14:51:32 +01:00
Transactions: make([][]byte, 0),
}
mockPayload3 = &types2.ExecutionPayload{
ParentHash: gointerfaces.ConvertHashToH256(startingHeadHash),
BlockHash: gointerfaces.ConvertHashToH256(payload3Hash),
ReceiptRoot: gointerfaces.ConvertHashToH256(libcommon.HexToHash("0x3")),
StateRoot: gointerfaces.ConvertHashToH256(libcommon.HexToHash("0x4")),
PrevRandao: gointerfaces.ConvertHashToH256(libcommon.HexToHash("0x0b3")),
2021-11-26 14:51:32 +01:00
LogsBloom: gointerfaces.ConvertBytesToH2048(make([]byte, 256)),
ExtraData: make([]byte, 0),
BaseFeePerGas: gointerfaces.ConvertHashToH256(libcommon.HexToHash("0x0b3")),
2021-11-26 14:51:32 +01:00
BlockNumber: 51,
GasLimit: 52,
GasUsed: 4,
Timestamp: 4,
Coinbase: gointerfaces.ConvertAddressToH160(libcommon.HexToAddress("0x1")),
2021-11-26 14:51:32 +01:00
Transactions: make([][]byte, 0),
}
)
2021-11-27 16:29:46 +01:00
func makeTestDb(ctx context.Context, db kv.RwDB) {
tx, _ := db.BeginRw(ctx)
rawdb.WriteHeadBlockHash(tx, startingHeadHash)
rawdb.WriteHeaderNumber(tx, startingHeadHash, 50)
_ = tx.Commit()
}
2021-11-26 14:51:32 +01:00
func TestMockDownloadRequest(t *testing.T) {
2022-12-19 10:56:57 +07:00
db := memdb.NewTestDB(t)
2021-11-26 14:51:32 +01:00
ctx := context.Background()
require := require.New(t)
2021-11-27 16:29:46 +01:00
makeTestDb(ctx, db)
hd := headerdownload.NewHeaderDownload(0, 0, nil, nil)
hd.SetPOSSync(true)
events := shards.NewEvents()
backend := NewEthBackendServer(ctx, nil, db, events, nil, &chain.Config{TerminalTotalDifficulty: libcommon.Big1}, nil, hd, false)
2021-11-26 14:51:32 +01:00
var err error
New Engine API semantics (Kiln v1) (#3340) * Disable PoS sync temporarily * Resore PoS sync * Handle Ctrl^C in HeadersPOS * Consistent naming * Extract verifyAndSavePoSHeader & downloadMissingPoSHeaders * Preparation for EngineForkChoiceUpdated re-orgs * Extract ForkingPoint * Comments * New proto for Engine API * EngineExecutePayload -> EngineNewPayload * Return INVALID_BLOCK_HASH if block hash is invalid * Return EngineStatus_ACCEPTED for side chain blocks * Update erigon-lib (PR 268) * Fix payload2Hash * reverseDownloadCh -> beaconPayloadCh * Update erigon-lib * Engine API updated * ExecutionStatus -> PayloadStatus * Introduce forkChoiceCh * Mock ForkChoiceMessage/PayloadStatus * Add ValidationError to PayloadStatus * Small clean-ups * Add INVALID_TERMINAL_BLOCK to EngineStatus * Add a comment * Extract handleNewPayload & handleForkChoice * Partially implement handleForkChoice * Update erigon-lib * short vs long re-org * Move header insertion out of downloadMissingPoSHeaders * Update erigon-lib * Refactor ProcessSegmentPOS * Fix imports * Wire downloadMissingPoSHeaders into handleForkChoice * evictOldPendingPayloads * nolint:unused for assertSegment * Try nolint instead of nolint:unused * Small comment improvements * HeadHeaderHash/StageProgress in handleForkChoice * TODO: bodyDownloader.AddToPrefetch(block) * Review call suggestions * Don't use ReadHeaderNumber in ProcessSegmentPOS * Don't leave ethbackend waiting when server is stopping * Update erigon-lib * More explicit signature of downloadMissingPoSHeaders
2022-02-09 08:33:22 +01:00
var reply *remote.EnginePayloadStatus
2021-11-26 14:51:32 +01:00
done := make(chan bool)
go func() {
reply, err = backend.EngineNewPayload(ctx, mockPayload1)
2021-11-26 14:51:32 +01:00
done <- true
}()
hd.BeaconRequestList.WaitForRequest(true, false)
hd.PayloadStatusCh <- engineapi.PayloadStatus{Status: remote.EngineStatus_SYNCING}
2021-11-26 14:51:32 +01:00
<-done
require.NoError(err)
New Engine API semantics (Kiln v1) (#3340) * Disable PoS sync temporarily * Resore PoS sync * Handle Ctrl^C in HeadersPOS * Consistent naming * Extract verifyAndSavePoSHeader & downloadMissingPoSHeaders * Preparation for EngineForkChoiceUpdated re-orgs * Extract ForkingPoint * Comments * New proto for Engine API * EngineExecutePayload -> EngineNewPayload * Return INVALID_BLOCK_HASH if block hash is invalid * Return EngineStatus_ACCEPTED for side chain blocks * Update erigon-lib (PR 268) * Fix payload2Hash * reverseDownloadCh -> beaconPayloadCh * Update erigon-lib * Engine API updated * ExecutionStatus -> PayloadStatus * Introduce forkChoiceCh * Mock ForkChoiceMessage/PayloadStatus * Add ValidationError to PayloadStatus * Small clean-ups * Add INVALID_TERMINAL_BLOCK to EngineStatus * Add a comment * Extract handleNewPayload & handleForkChoice * Partially implement handleForkChoice * Update erigon-lib * short vs long re-org * Move header insertion out of downloadMissingPoSHeaders * Update erigon-lib * Refactor ProcessSegmentPOS * Fix imports * Wire downloadMissingPoSHeaders into handleForkChoice * evictOldPendingPayloads * nolint:unused for assertSegment * Try nolint instead of nolint:unused * Small comment improvements * HeadHeaderHash/StageProgress in handleForkChoice * TODO: bodyDownloader.AddToPrefetch(block) * Review call suggestions * Don't use ReadHeaderNumber in ProcessSegmentPOS * Don't leave ethbackend waiting when server is stopping * Update erigon-lib * More explicit signature of downloadMissingPoSHeaders
2022-02-09 08:33:22 +01:00
require.Equal(reply.Status, remote.EngineStatus_SYNCING)
require.Nil(reply.LatestValidHash)
2021-11-26 14:51:32 +01:00
// If we get another request we don't need to process it with processDownloadCh and ignore it and return Syncing status
2021-11-26 14:51:32 +01:00
go func() {
reply, err = backend.EngineNewPayload(ctx, mockPayload2)
2021-11-26 14:51:32 +01:00
done <- true
}()
<-done
// Same result as before
require.NoError(err)
New Engine API semantics (Kiln v1) (#3340) * Disable PoS sync temporarily * Resore PoS sync * Handle Ctrl^C in HeadersPOS * Consistent naming * Extract verifyAndSavePoSHeader & downloadMissingPoSHeaders * Preparation for EngineForkChoiceUpdated re-orgs * Extract ForkingPoint * Comments * New proto for Engine API * EngineExecutePayload -> EngineNewPayload * Return INVALID_BLOCK_HASH if block hash is invalid * Return EngineStatus_ACCEPTED for side chain blocks * Update erigon-lib (PR 268) * Fix payload2Hash * reverseDownloadCh -> beaconPayloadCh * Update erigon-lib * Engine API updated * ExecutionStatus -> PayloadStatus * Introduce forkChoiceCh * Mock ForkChoiceMessage/PayloadStatus * Add ValidationError to PayloadStatus * Small clean-ups * Add INVALID_TERMINAL_BLOCK to EngineStatus * Add a comment * Extract handleNewPayload & handleForkChoice * Partially implement handleForkChoice * Update erigon-lib * short vs long re-org * Move header insertion out of downloadMissingPoSHeaders * Update erigon-lib * Refactor ProcessSegmentPOS * Fix imports * Wire downloadMissingPoSHeaders into handleForkChoice * evictOldPendingPayloads * nolint:unused for assertSegment * Try nolint instead of nolint:unused * Small comment improvements * HeadHeaderHash/StageProgress in handleForkChoice * TODO: bodyDownloader.AddToPrefetch(block) * Review call suggestions * Don't use ReadHeaderNumber in ProcessSegmentPOS * Don't leave ethbackend waiting when server is stopping * Update erigon-lib * More explicit signature of downloadMissingPoSHeaders
2022-02-09 08:33:22 +01:00
require.Equal(reply.Status, remote.EngineStatus_SYNCING)
require.Nil(reply.LatestValidHash)
2021-11-26 14:51:32 +01:00
// However if we simulate that we finish reverse downloading the chain by updating the head, we just execute 1:1
2021-11-27 16:29:46 +01:00
tx, _ := db.BeginRw(ctx)
2021-11-26 14:51:32 +01:00
rawdb.WriteHeadBlockHash(tx, payload1Hash)
rawdb.WriteHeaderNumber(tx, payload1Hash, 100)
_ = tx.Commit()
// Now we try to sync the next payload again
go func() {
reply, err = backend.EngineNewPayload(ctx, mockPayload2)
2021-11-26 14:51:32 +01:00
done <- true
}()
<-done
require.NoError(err)
New Engine API semantics (Kiln v1) (#3340) * Disable PoS sync temporarily * Resore PoS sync * Handle Ctrl^C in HeadersPOS * Consistent naming * Extract verifyAndSavePoSHeader & downloadMissingPoSHeaders * Preparation for EngineForkChoiceUpdated re-orgs * Extract ForkingPoint * Comments * New proto for Engine API * EngineExecutePayload -> EngineNewPayload * Return INVALID_BLOCK_HASH if block hash is invalid * Return EngineStatus_ACCEPTED for side chain blocks * Update erigon-lib (PR 268) * Fix payload2Hash * reverseDownloadCh -> beaconPayloadCh * Update erigon-lib * Engine API updated * ExecutionStatus -> PayloadStatus * Introduce forkChoiceCh * Mock ForkChoiceMessage/PayloadStatus * Add ValidationError to PayloadStatus * Small clean-ups * Add INVALID_TERMINAL_BLOCK to EngineStatus * Add a comment * Extract handleNewPayload & handleForkChoice * Partially implement handleForkChoice * Update erigon-lib * short vs long re-org * Move header insertion out of downloadMissingPoSHeaders * Update erigon-lib * Refactor ProcessSegmentPOS * Fix imports * Wire downloadMissingPoSHeaders into handleForkChoice * evictOldPendingPayloads * nolint:unused for assertSegment * Try nolint instead of nolint:unused * Small comment improvements * HeadHeaderHash/StageProgress in handleForkChoice * TODO: bodyDownloader.AddToPrefetch(block) * Review call suggestions * Don't use ReadHeaderNumber in ProcessSegmentPOS * Don't leave ethbackend waiting when server is stopping * Update erigon-lib * More explicit signature of downloadMissingPoSHeaders
2022-02-09 08:33:22 +01:00
require.Equal(reply.Status, remote.EngineStatus_SYNCING)
require.Nil(reply.LatestValidHash)
2021-11-26 14:51:32 +01:00
}
2021-11-26 11:59:05 +01:00
func TestMockValidExecution(t *testing.T) {
2022-12-19 10:56:57 +07:00
db := memdb.NewTestDB(t)
2021-11-26 11:59:05 +01:00
ctx := context.Background()
require := require.New(t)
2021-11-27 16:29:46 +01:00
makeTestDb(ctx, db)
2021-11-26 11:59:05 +01:00
hd := headerdownload.NewHeaderDownload(0, 0, nil, nil)
hd.SetPOSSync(true)
2021-11-26 11:59:05 +01:00
events := shards.NewEvents()
backend := NewEthBackendServer(ctx, nil, db, events, nil, &chain.Config{TerminalTotalDifficulty: libcommon.Big1}, nil, hd, false)
2021-11-26 11:59:05 +01:00
var err error
New Engine API semantics (Kiln v1) (#3340) * Disable PoS sync temporarily * Resore PoS sync * Handle Ctrl^C in HeadersPOS * Consistent naming * Extract verifyAndSavePoSHeader & downloadMissingPoSHeaders * Preparation for EngineForkChoiceUpdated re-orgs * Extract ForkingPoint * Comments * New proto for Engine API * EngineExecutePayload -> EngineNewPayload * Return INVALID_BLOCK_HASH if block hash is invalid * Return EngineStatus_ACCEPTED for side chain blocks * Update erigon-lib (PR 268) * Fix payload2Hash * reverseDownloadCh -> beaconPayloadCh * Update erigon-lib * Engine API updated * ExecutionStatus -> PayloadStatus * Introduce forkChoiceCh * Mock ForkChoiceMessage/PayloadStatus * Add ValidationError to PayloadStatus * Small clean-ups * Add INVALID_TERMINAL_BLOCK to EngineStatus * Add a comment * Extract handleNewPayload & handleForkChoice * Partially implement handleForkChoice * Update erigon-lib * short vs long re-org * Move header insertion out of downloadMissingPoSHeaders * Update erigon-lib * Refactor ProcessSegmentPOS * Fix imports * Wire downloadMissingPoSHeaders into handleForkChoice * evictOldPendingPayloads * nolint:unused for assertSegment * Try nolint instead of nolint:unused * Small comment improvements * HeadHeaderHash/StageProgress in handleForkChoice * TODO: bodyDownloader.AddToPrefetch(block) * Review call suggestions * Don't use ReadHeaderNumber in ProcessSegmentPOS * Don't leave ethbackend waiting when server is stopping * Update erigon-lib * More explicit signature of downloadMissingPoSHeaders
2022-02-09 08:33:22 +01:00
var reply *remote.EnginePayloadStatus
2021-11-26 11:59:05 +01:00
done := make(chan bool)
go func() {
reply, err = backend.EngineNewPayload(ctx, mockPayload3)
2021-11-26 11:59:05 +01:00
done <- true
}()
hd.BeaconRequestList.WaitForRequest(true, false)
2021-11-26 11:59:05 +01:00
hd.PayloadStatusCh <- engineapi.PayloadStatus{
New Engine API semantics (Kiln v1) (#3340) * Disable PoS sync temporarily * Resore PoS sync * Handle Ctrl^C in HeadersPOS * Consistent naming * Extract verifyAndSavePoSHeader & downloadMissingPoSHeaders * Preparation for EngineForkChoiceUpdated re-orgs * Extract ForkingPoint * Comments * New proto for Engine API * EngineExecutePayload -> EngineNewPayload * Return INVALID_BLOCK_HASH if block hash is invalid * Return EngineStatus_ACCEPTED for side chain blocks * Update erigon-lib (PR 268) * Fix payload2Hash * reverseDownloadCh -> beaconPayloadCh * Update erigon-lib * Engine API updated * ExecutionStatus -> PayloadStatus * Introduce forkChoiceCh * Mock ForkChoiceMessage/PayloadStatus * Add ValidationError to PayloadStatus * Small clean-ups * Add INVALID_TERMINAL_BLOCK to EngineStatus * Add a comment * Extract handleNewPayload & handleForkChoice * Partially implement handleForkChoice * Update erigon-lib * short vs long re-org * Move header insertion out of downloadMissingPoSHeaders * Update erigon-lib * Refactor ProcessSegmentPOS * Fix imports * Wire downloadMissingPoSHeaders into handleForkChoice * evictOldPendingPayloads * nolint:unused for assertSegment * Try nolint instead of nolint:unused * Small comment improvements * HeadHeaderHash/StageProgress in handleForkChoice * TODO: bodyDownloader.AddToPrefetch(block) * Review call suggestions * Don't use ReadHeaderNumber in ProcessSegmentPOS * Don't leave ethbackend waiting when server is stopping * Update erigon-lib * More explicit signature of downloadMissingPoSHeaders
2022-02-09 08:33:22 +01:00
Status: remote.EngineStatus_VALID,
LatestValidHash: payload3Hash,
2021-11-26 11:59:05 +01:00
}
<-done
require.NoError(err)
New Engine API semantics (Kiln v1) (#3340) * Disable PoS sync temporarily * Resore PoS sync * Handle Ctrl^C in HeadersPOS * Consistent naming * Extract verifyAndSavePoSHeader & downloadMissingPoSHeaders * Preparation for EngineForkChoiceUpdated re-orgs * Extract ForkingPoint * Comments * New proto for Engine API * EngineExecutePayload -> EngineNewPayload * Return INVALID_BLOCK_HASH if block hash is invalid * Return EngineStatus_ACCEPTED for side chain blocks * Update erigon-lib (PR 268) * Fix payload2Hash * reverseDownloadCh -> beaconPayloadCh * Update erigon-lib * Engine API updated * ExecutionStatus -> PayloadStatus * Introduce forkChoiceCh * Mock ForkChoiceMessage/PayloadStatus * Add ValidationError to PayloadStatus * Small clean-ups * Add INVALID_TERMINAL_BLOCK to EngineStatus * Add a comment * Extract handleNewPayload & handleForkChoice * Partially implement handleForkChoice * Update erigon-lib * short vs long re-org * Move header insertion out of downloadMissingPoSHeaders * Update erigon-lib * Refactor ProcessSegmentPOS * Fix imports * Wire downloadMissingPoSHeaders into handleForkChoice * evictOldPendingPayloads * nolint:unused for assertSegment * Try nolint instead of nolint:unused * Small comment improvements * HeadHeaderHash/StageProgress in handleForkChoice * TODO: bodyDownloader.AddToPrefetch(block) * Review call suggestions * Don't use ReadHeaderNumber in ProcessSegmentPOS * Don't leave ethbackend waiting when server is stopping * Update erigon-lib * More explicit signature of downloadMissingPoSHeaders
2022-02-09 08:33:22 +01:00
require.Equal(reply.Status, remote.EngineStatus_VALID)
2021-11-26 11:59:05 +01:00
replyHash := gointerfaces.ConvertH256ToHash(reply.LatestValidHash)
2021-11-26 14:51:32 +01:00
require.Equal(replyHash[:], payload3Hash[:])
2021-11-26 11:59:05 +01:00
}
func TestMockInvalidExecution(t *testing.T) {
2022-12-19 10:56:57 +07:00
db := memdb.NewTestDB(t)
2021-11-26 11:59:05 +01:00
ctx := context.Background()
require := require.New(t)
2021-11-27 16:29:46 +01:00
makeTestDb(ctx, db)
2021-11-26 11:59:05 +01:00
hd := headerdownload.NewHeaderDownload(0, 0, nil, nil)
hd.SetPOSSync(true)
2021-11-26 11:59:05 +01:00
events := shards.NewEvents()
backend := NewEthBackendServer(ctx, nil, db, events, nil, &chain.Config{TerminalTotalDifficulty: libcommon.Big1}, nil, hd, false)
2021-11-26 11:59:05 +01:00
var err error
New Engine API semantics (Kiln v1) (#3340) * Disable PoS sync temporarily * Resore PoS sync * Handle Ctrl^C in HeadersPOS * Consistent naming * Extract verifyAndSavePoSHeader & downloadMissingPoSHeaders * Preparation for EngineForkChoiceUpdated re-orgs * Extract ForkingPoint * Comments * New proto for Engine API * EngineExecutePayload -> EngineNewPayload * Return INVALID_BLOCK_HASH if block hash is invalid * Return EngineStatus_ACCEPTED for side chain blocks * Update erigon-lib (PR 268) * Fix payload2Hash * reverseDownloadCh -> beaconPayloadCh * Update erigon-lib * Engine API updated * ExecutionStatus -> PayloadStatus * Introduce forkChoiceCh * Mock ForkChoiceMessage/PayloadStatus * Add ValidationError to PayloadStatus * Small clean-ups * Add INVALID_TERMINAL_BLOCK to EngineStatus * Add a comment * Extract handleNewPayload & handleForkChoice * Partially implement handleForkChoice * Update erigon-lib * short vs long re-org * Move header insertion out of downloadMissingPoSHeaders * Update erigon-lib * Refactor ProcessSegmentPOS * Fix imports * Wire downloadMissingPoSHeaders into handleForkChoice * evictOldPendingPayloads * nolint:unused for assertSegment * Try nolint instead of nolint:unused * Small comment improvements * HeadHeaderHash/StageProgress in handleForkChoice * TODO: bodyDownloader.AddToPrefetch(block) * Review call suggestions * Don't use ReadHeaderNumber in ProcessSegmentPOS * Don't leave ethbackend waiting when server is stopping * Update erigon-lib * More explicit signature of downloadMissingPoSHeaders
2022-02-09 08:33:22 +01:00
var reply *remote.EnginePayloadStatus
2021-11-26 11:59:05 +01:00
done := make(chan bool)
go func() {
reply, err = backend.EngineNewPayload(ctx, mockPayload3)
2021-11-26 11:59:05 +01:00
done <- true
}()
hd.BeaconRequestList.WaitForRequest(true, false)
2021-11-30 18:14:34 +01:00
// Simulate invalid status
hd.PayloadStatusCh <- engineapi.PayloadStatus{
New Engine API semantics (Kiln v1) (#3340) * Disable PoS sync temporarily * Resore PoS sync * Handle Ctrl^C in HeadersPOS * Consistent naming * Extract verifyAndSavePoSHeader & downloadMissingPoSHeaders * Preparation for EngineForkChoiceUpdated re-orgs * Extract ForkingPoint * Comments * New proto for Engine API * EngineExecutePayload -> EngineNewPayload * Return INVALID_BLOCK_HASH if block hash is invalid * Return EngineStatus_ACCEPTED for side chain blocks * Update erigon-lib (PR 268) * Fix payload2Hash * reverseDownloadCh -> beaconPayloadCh * Update erigon-lib * Engine API updated * ExecutionStatus -> PayloadStatus * Introduce forkChoiceCh * Mock ForkChoiceMessage/PayloadStatus * Add ValidationError to PayloadStatus * Small clean-ups * Add INVALID_TERMINAL_BLOCK to EngineStatus * Add a comment * Extract handleNewPayload & handleForkChoice * Partially implement handleForkChoice * Update erigon-lib * short vs long re-org * Move header insertion out of downloadMissingPoSHeaders * Update erigon-lib * Refactor ProcessSegmentPOS * Fix imports * Wire downloadMissingPoSHeaders into handleForkChoice * evictOldPendingPayloads * nolint:unused for assertSegment * Try nolint instead of nolint:unused * Small comment improvements * HeadHeaderHash/StageProgress in handleForkChoice * TODO: bodyDownloader.AddToPrefetch(block) * Review call suggestions * Don't use ReadHeaderNumber in ProcessSegmentPOS * Don't leave ethbackend waiting when server is stopping * Update erigon-lib * More explicit signature of downloadMissingPoSHeaders
2022-02-09 08:33:22 +01:00
Status: remote.EngineStatus_INVALID,
LatestValidHash: startingHeadHash,
2021-11-26 11:59:05 +01:00
}
<-done
require.NoError(err)
New Engine API semantics (Kiln v1) (#3340) * Disable PoS sync temporarily * Resore PoS sync * Handle Ctrl^C in HeadersPOS * Consistent naming * Extract verifyAndSavePoSHeader & downloadMissingPoSHeaders * Preparation for EngineForkChoiceUpdated re-orgs * Extract ForkingPoint * Comments * New proto for Engine API * EngineExecutePayload -> EngineNewPayload * Return INVALID_BLOCK_HASH if block hash is invalid * Return EngineStatus_ACCEPTED for side chain blocks * Update erigon-lib (PR 268) * Fix payload2Hash * reverseDownloadCh -> beaconPayloadCh * Update erigon-lib * Engine API updated * ExecutionStatus -> PayloadStatus * Introduce forkChoiceCh * Mock ForkChoiceMessage/PayloadStatus * Add ValidationError to PayloadStatus * Small clean-ups * Add INVALID_TERMINAL_BLOCK to EngineStatus * Add a comment * Extract handleNewPayload & handleForkChoice * Partially implement handleForkChoice * Update erigon-lib * short vs long re-org * Move header insertion out of downloadMissingPoSHeaders * Update erigon-lib * Refactor ProcessSegmentPOS * Fix imports * Wire downloadMissingPoSHeaders into handleForkChoice * evictOldPendingPayloads * nolint:unused for assertSegment * Try nolint instead of nolint:unused * Small comment improvements * HeadHeaderHash/StageProgress in handleForkChoice * TODO: bodyDownloader.AddToPrefetch(block) * Review call suggestions * Don't use ReadHeaderNumber in ProcessSegmentPOS * Don't leave ethbackend waiting when server is stopping * Update erigon-lib * More explicit signature of downloadMissingPoSHeaders
2022-02-09 08:33:22 +01:00
require.Equal(reply.Status, remote.EngineStatus_INVALID)
2021-11-26 11:59:05 +01:00
replyHash := gointerfaces.ConvertH256ToHash(reply.LatestValidHash)
2021-11-26 14:51:32 +01:00
require.Equal(replyHash[:], startingHeadHash[:])
2021-11-26 11:59:05 +01:00
}
func TestNoTTD(t *testing.T) {
2022-12-19 10:56:57 +07:00
db := memdb.NewTestDB(t)
2021-11-26 11:59:05 +01:00
ctx := context.Background()
require := require.New(t)
2021-11-27 16:29:46 +01:00
makeTestDb(ctx, db)
2021-11-26 11:59:05 +01:00
hd := headerdownload.NewHeaderDownload(0, 0, nil, nil)
2021-11-26 11:59:05 +01:00
events := shards.NewEvents()
backend := NewEthBackendServer(ctx, nil, db, events, nil, &chain.Config{}, nil, hd, false)
2021-11-26 11:59:05 +01:00
var err error
done := make(chan bool)
go func() {
_, err = backend.EngineNewPayload(ctx, &types2.ExecutionPayload{
ParentHash: gointerfaces.ConvertHashToH256(libcommon.HexToHash("0x2")),
BlockHash: gointerfaces.ConvertHashToH256(libcommon.HexToHash("0xe6a580606b065e08034dcd6eea026cfdcbd3b41918d98b41cb9bf797d0c27033")),
ReceiptRoot: gointerfaces.ConvertHashToH256(libcommon.HexToHash("0x4")),
StateRoot: gointerfaces.ConvertHashToH256(libcommon.HexToHash("0x4")),
PrevRandao: gointerfaces.ConvertHashToH256(libcommon.HexToHash("0x0b3")),
2021-11-26 11:59:05 +01:00
LogsBloom: gointerfaces.ConvertBytesToH2048(make([]byte, 256)),
ExtraData: make([]byte, 0),
BaseFeePerGas: gointerfaces.ConvertHashToH256(libcommon.HexToHash("0x0b3")),
2021-11-26 14:51:32 +01:00
BlockNumber: 51,
2021-11-26 11:59:05 +01:00
GasLimit: 52,
GasUsed: 4,
Timestamp: 4,
Coinbase: gointerfaces.ConvertAddressToH160(libcommon.HexToAddress("0x1")),
2021-11-26 11:59:05 +01:00
Transactions: make([][]byte, 0),
})
done <- true
}()
<-done
require.Equal(err.Error(), "not a proof-of-stake chain")
}