Skip to content

Commit

Permalink
Merge pull request #236 from ethpandaops/pk910/request-simulation
Browse files Browse the repository at this point in the history
request result simulation
  • Loading branch information
pk910 authored Feb 17, 2025
2 parents 562267b + 81f56df commit d0788d5
Show file tree
Hide file tree
Showing 32 changed files with 1,076 additions and 167 deletions.
84 changes: 45 additions & 39 deletions clients/consensus/chainspec.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,45 +20,51 @@ type ForkVersion struct {

// https://github.com/ethereum/consensus-specs/blob/dev/configs/mainnet.yaml
type ChainSpec struct {
PresetBase string `yaml:"PRESET_BASE"`
ConfigName string `yaml:"CONFIG_NAME" check-if:"false"`
MinGenesisTime time.Time `yaml:"MIN_GENESIS_TIME"`
GenesisForkVersion phase0.Version `yaml:"GENESIS_FORK_VERSION"`
AltairForkVersion phase0.Version `yaml:"ALTAIR_FORK_VERSION"`
AltairForkEpoch *uint64 `yaml:"ALTAIR_FORK_EPOCH"`
BellatrixForkVersion phase0.Version `yaml:"BELLATRIX_FORK_VERSION"`
BellatrixForkEpoch *uint64 `yaml:"BELLATRIX_FORK_EPOCH"`
CapellaForkVersion phase0.Version `yaml:"CAPELLA_FORK_VERSION"`
CapellaForkEpoch *uint64 `yaml:"CAPELLA_FORK_EPOCH"`
DenebForkVersion phase0.Version `yaml:"DENEB_FORK_VERSION"`
DenebForkEpoch *uint64 `yaml:"DENEB_FORK_EPOCH"`
ElectraForkVersion phase0.Version `yaml:"ELECTRA_FORK_VERSION" check-if-fork:"ElectraForkEpoch"`
ElectraForkEpoch *uint64 `yaml:"ELECTRA_FORK_EPOCH"`
Eip7594ForkVersion phase0.Version `yaml:"EIP7594_FORK_VERSION" check-if-fork:"Eip7594ForkEpoch"`
Eip7594ForkEpoch *uint64 `yaml:"EIP7594_FORK_EPOCH"`
SecondsPerSlot time.Duration `yaml:"SECONDS_PER_SLOT"`
SlotsPerEpoch uint64 `yaml:"SLOTS_PER_EPOCH"`
EpochsPerHistoricalVector uint64 `yaml:"EPOCHS_PER_HISTORICAL_VECTOR"`
EpochsPerSlashingVector uint64 `yaml:"EPOCHS_PER_SLASHINGS_VECTOR"`
EpochsPerSyncCommitteePeriod uint64 `yaml:"EPOCHS_PER_SYNC_COMMITTEE_PERIOD"`
MinSeedLookahead uint64 `yaml:"MIN_SEED_LOOKAHEAD"`
ShuffleRoundCount uint64 `yaml:"SHUFFLE_ROUND_COUNT"`
MaxEffectiveBalance uint64 `yaml:"MAX_EFFECTIVE_BALANCE"`
MaxEffectiveBalanceElectra uint64 `yaml:"MAX_EFFECTIVE_BALANCE_ELECTRA" check-if-fork:"ElectraForkEpoch"`
TargetCommitteeSize uint64 `yaml:"TARGET_COMMITTEE_SIZE"`
MaxCommitteesPerSlot uint64 `yaml:"MAX_COMMITTEES_PER_SLOT"`
MinPerEpochChurnLimit uint64 `yaml:"MIN_PER_EPOCH_CHURN_LIMIT"`
ChurnLimitQuotient uint64 `yaml:"CHURN_LIMIT_QUOTIENT"`
DomainBeaconProposer phase0.DomainType `yaml:"DOMAIN_BEACON_PROPOSER"`
DomainBeaconAttester phase0.DomainType `yaml:"DOMAIN_BEACON_ATTESTER"`
DomainSyncCommittee phase0.DomainType `yaml:"DOMAIN_SYNC_COMMITTEE"`
SyncCommitteeSize uint64 `yaml:"SYNC_COMMITTEE_SIZE"`
DepositContractAddress []byte `yaml:"DEPOSIT_CONTRACT_ADDRESS"`
MaxConsolidationRequestsPerPayload uint64 `yaml:"MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD" check-if-fork:"ElectraForkEpoch"`
MaxWithdrawalRequestsPerPayload uint64 `yaml:"MAX_WITHDRAWAL_REQUESTS_PER_PAYLOAD" check-if-fork:"ElectraForkEpoch"`
DepositChainId uint64 `yaml:"DEPOSIT_CHAIN_ID"`
MinActivationBalance uint64 `yaml:"MIN_ACTIVATION_BALANCE"`
ShardCommitteePeriod uint64 `yaml:"SHARD_COMMITTEE_PERIOD"`
PresetBase string `yaml:"PRESET_BASE"`
ConfigName string `yaml:"CONFIG_NAME" check-if:"false"`
MinGenesisTime time.Time `yaml:"MIN_GENESIS_TIME"`
GenesisForkVersion phase0.Version `yaml:"GENESIS_FORK_VERSION"`
AltairForkVersion phase0.Version `yaml:"ALTAIR_FORK_VERSION"`
AltairForkEpoch *uint64 `yaml:"ALTAIR_FORK_EPOCH"`
BellatrixForkVersion phase0.Version `yaml:"BELLATRIX_FORK_VERSION"`
BellatrixForkEpoch *uint64 `yaml:"BELLATRIX_FORK_EPOCH"`
CapellaForkVersion phase0.Version `yaml:"CAPELLA_FORK_VERSION"`
CapellaForkEpoch *uint64 `yaml:"CAPELLA_FORK_EPOCH"`
DenebForkVersion phase0.Version `yaml:"DENEB_FORK_VERSION"`
DenebForkEpoch *uint64 `yaml:"DENEB_FORK_EPOCH"`
ElectraForkVersion phase0.Version `yaml:"ELECTRA_FORK_VERSION" check-if-fork:"ElectraForkEpoch"`
ElectraForkEpoch *uint64 `yaml:"ELECTRA_FORK_EPOCH" check-if-fork:"ElectraForkEpoch"`
Eip7594ForkVersion phase0.Version `yaml:"EIP7594_FORK_VERSION" check-if-fork:"Eip7594ForkEpoch"`
Eip7594ForkEpoch *uint64 `yaml:"EIP7594_FORK_EPOCH" check-if-fork:"Eip7594ForkEpoch"`
SecondsPerSlot time.Duration `yaml:"SECONDS_PER_SLOT"`
SlotsPerEpoch uint64 `yaml:"SLOTS_PER_EPOCH"`
EpochsPerHistoricalVector uint64 `yaml:"EPOCHS_PER_HISTORICAL_VECTOR"`
EpochsPerSlashingVector uint64 `yaml:"EPOCHS_PER_SLASHINGS_VECTOR"`
EpochsPerSyncCommitteePeriod uint64 `yaml:"EPOCHS_PER_SYNC_COMMITTEE_PERIOD"`
MinSeedLookahead uint64 `yaml:"MIN_SEED_LOOKAHEAD"`
ShuffleRoundCount uint64 `yaml:"SHUFFLE_ROUND_COUNT"`
MaxEffectiveBalance uint64 `yaml:"MAX_EFFECTIVE_BALANCE"`
MaxEffectiveBalanceElectra uint64 `yaml:"MAX_EFFECTIVE_BALANCE_ELECTRA" check-if-fork:"ElectraForkEpoch"`
TargetCommitteeSize uint64 `yaml:"TARGET_COMMITTEE_SIZE"`
MaxCommitteesPerSlot uint64 `yaml:"MAX_COMMITTEES_PER_SLOT"`
MinPerEpochChurnLimit uint64 `yaml:"MIN_PER_EPOCH_CHURN_LIMIT"`
ChurnLimitQuotient uint64 `yaml:"CHURN_LIMIT_QUOTIENT"`
DomainBeaconProposer phase0.DomainType `yaml:"DOMAIN_BEACON_PROPOSER"`
DomainBeaconAttester phase0.DomainType `yaml:"DOMAIN_BEACON_ATTESTER"`
DomainSyncCommittee phase0.DomainType `yaml:"DOMAIN_SYNC_COMMITTEE"`
SyncCommitteeSize uint64 `yaml:"SYNC_COMMITTEE_SIZE"`
DepositContractAddress []byte `yaml:"DEPOSIT_CONTRACT_ADDRESS"`
MaxConsolidationRequestsPerPayload uint64 `yaml:"MAX_CONSOLIDATION_REQUESTS_PER_PAYLOAD" check-if-fork:"ElectraForkEpoch"`
MaxWithdrawalRequestsPerPayload uint64 `yaml:"MAX_WITHDRAWAL_REQUESTS_PER_PAYLOAD" check-if-fork:"ElectraForkEpoch"`
DepositChainId uint64 `yaml:"DEPOSIT_CHAIN_ID"`
MinActivationBalance uint64 `yaml:"MIN_ACTIVATION_BALANCE"`
MaxPendingPartialsPerWithdrawalsSweep uint64 `yaml:"MAX_PENDING_PARTIALS_PER_WITHDRAWALS_SWEEP" check-if-fork:"ElectraForkEpoch"`
PendingPartialWithdrawalsLimit uint64 `yaml:"PENDING_PARTIAL_WITHDRAWALS_LIMIT" check-if-fork:"ElectraForkEpoch"`
PendingConsolidationsLimit uint64 `yaml:"PENDING_CONSOLIDATIONS_LIMIT" check-if-fork:"ElectraForkEpoch"`
MinPerEpochChurnLimitElectra uint64 `yaml:"MIN_PER_EPOCH_CHURN_LIMIT_ELECTRA" check-if-fork:"ElectraForkEpoch"`
MaxPerEpochActivationExitChurnLimit uint64 `yaml:"MAX_PER_EPOCH_ACTIVATION_EXIT_CHURN_LIMIT" check-if-fork:"ElectraForkEpoch"`
EffectiveBalanceIncrement uint64 `yaml:"EFFECTIVE_BALANCE_INCREMENT"`
ShardCommitteePeriod uint64 `yaml:"SHARD_COMMITTEE_PERIOD"`

// EIP7594: PeerDAS
NumberOfColumns *uint64 `yaml:"NUMBER_OF_COLUMNS" check-if-fork:"Eip7594ForkEpoch"`
Expand Down
2 changes: 1 addition & 1 deletion db/consolidation_request_txs.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func InsertConsolidationRequestTxs(consolidationTxs []*dbtypes.ConsolidationRequ
argIdx += fieldCount
}
fmt.Fprint(&sql, EngineQuery(map[dbtypes.DBEngineType]string{
dbtypes.DBEnginePgsql: " ON CONFLICT (block_root, block_index) DO UPDATE SET source_index = excluded.source_index, target_index = excluded.target_index, fork_id = excluded.fork_id",
dbtypes.DBEnginePgsql: " ON CONFLICT (block_root, block_index) DO UPDATE SET source_index = excluded.source_index, target_index = excluded.target_index, dequeue_block = excluded.dequeue_block, fork_id = excluded.fork_id",
dbtypes.DBEngineSqlite: "",
}))

Expand Down
12 changes: 7 additions & 5 deletions db/consolidation_requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ func InsertConsolidationRequests(consolidations []*dbtypes.ConsolidationRequest,
dbtypes.DBEnginePgsql: "INSERT INTO consolidation_requests ",
dbtypes.DBEngineSqlite: "INSERT OR REPLACE INTO consolidation_requests ",
}),
"(slot_number, slot_root, slot_index, orphaned, fork_id, source_address, source_index, source_pubkey, target_index, target_pubkey, tx_hash, block_number)",
"(slot_number, slot_root, slot_index, orphaned, fork_id, source_address, source_index, source_pubkey, target_index, target_pubkey, tx_hash, block_number, result)",
" VALUES ",
)
argIdx := 0
fieldCount := 12
fieldCount := 13

args := make([]interface{}, len(consolidations)*fieldCount)
for i, consolidation := range consolidations {
Expand Down Expand Up @@ -47,10 +47,11 @@ func InsertConsolidationRequests(consolidations []*dbtypes.ConsolidationRequest,
args[argIdx+9] = consolidation.TargetPubkey[:]
args[argIdx+10] = consolidation.TxHash[:]
args[argIdx+11] = consolidation.BlockNumber
args[argIdx+12] = consolidation.Result
argIdx += fieldCount
}
fmt.Fprint(&sql, EngineQuery(map[dbtypes.DBEngineType]string{
dbtypes.DBEnginePgsql: " ON CONFLICT (slot_root, slot_index) DO UPDATE SET orphaned = excluded.orphaned, fork_id = excluded.fork_id",
dbtypes.DBEnginePgsql: " ON CONFLICT (slot_root, slot_index) DO UPDATE SET orphaned = excluded.orphaned, fork_id = excluded.fork_id, result = excluded.result",
dbtypes.DBEngineSqlite: "",
}))
_, err := tx.Exec(sql.String(), args...)
Expand All @@ -66,7 +67,7 @@ func GetConsolidationRequestsFiltered(offset uint64, limit uint32, canonicalFork
fmt.Fprint(&sql, `
WITH cte AS (
SELECT
slot_number, slot_root, slot_index, orphaned, fork_id, source_address, source_index, source_pubkey, target_index, target_pubkey, tx_hash, block_number
slot_number, slot_root, slot_index, orphaned, fork_id, source_address, source_index, source_pubkey, target_index, target_pubkey, tx_hash, block_number, result
FROM consolidation_requests
`)

Expand Down Expand Up @@ -173,7 +174,8 @@ func GetConsolidationRequestsFiltered(offset uint64, limit uint32, canonicalFork
0 AS target_index,
null AS target_pubkey,
null AS tx_hash,
0 AS block_number
0 AS block_number,
0 AS result
FROM cte
UNION ALL SELECT * FROM (
SELECT * FROM cte
Expand Down
14 changes: 14 additions & 0 deletions db/schema/pgsql/20250207221132_request-results.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-- +goose Up
-- +goose StatementBegin

ALTER TABLE public."consolidation_requests"
ADD "result" smallint NOT NULL DEFAULT 0;

ALTER TABLE public."withdrawal_requests"
ADD "result" smallint NOT NULL DEFAULT 0;

-- +goose StatementEnd
-- +goose Down
-- +goose StatementBegin
SELECT 'NOT SUPPORTED';
-- +goose StatementEnd
14 changes: 14 additions & 0 deletions db/schema/sqlite/20250207221132_request-results.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-- +goose Up
-- +goose StatementBegin

ALTER TABLE "consolidation_requests"
ADD "result" TINYINT NOT NULL DEFAULT 0;

ALTER TABLE "withdrawal_requests"
ADD "result" TINYINT NOT NULL DEFAULT 0;

-- +goose StatementEnd
-- +goose Down
-- +goose StatementBegin
SELECT 'NOT SUPPORTED';
-- +goose StatementEnd
2 changes: 1 addition & 1 deletion db/withdrawal_request_txs.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func InsertWithdrawalRequestTxs(withdrawalTxs []*dbtypes.WithdrawalRequestTx, tx
argIdx += fieldCount
}
fmt.Fprint(&sql, EngineQuery(map[dbtypes.DBEngineType]string{
dbtypes.DBEnginePgsql: " ON CONFLICT (block_root, block_index) DO UPDATE SET validator_index = excluded.validator_index, fork_id = excluded.fork_id",
dbtypes.DBEnginePgsql: " ON CONFLICT (block_root, block_index) DO UPDATE SET validator_index = excluded.validator_index, dequeue_block = excluded.dequeue_block, fork_id = excluded.fork_id",
dbtypes.DBEngineSqlite: "",
}))

Expand Down
12 changes: 7 additions & 5 deletions db/withdrawal_requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ func InsertWithdrawalRequests(elRequests []*dbtypes.WithdrawalRequest, tx *sqlx.
dbtypes.DBEnginePgsql: "INSERT INTO withdrawal_requests ",
dbtypes.DBEngineSqlite: "INSERT OR REPLACE INTO withdrawal_requests ",
}),
"(slot_number, slot_root, slot_index, orphaned, fork_id, source_address, validator_index, validator_pubkey, amount, tx_hash, block_number)",
"(slot_number, slot_root, slot_index, orphaned, fork_id, source_address, validator_index, validator_pubkey, amount, tx_hash, block_number, result)",
" VALUES ",
)
argIdx := 0
fieldCount := 11
fieldCount := 12

args := make([]any, len(elRequests)*fieldCount)
for i, elRequest := range elRequests {
Expand Down Expand Up @@ -47,10 +47,11 @@ func InsertWithdrawalRequests(elRequests []*dbtypes.WithdrawalRequest, tx *sqlx.
args[argIdx+8] = elRequest.Amount
args[argIdx+9] = elRequest.TxHash
args[argIdx+10] = elRequest.BlockNumber
args[argIdx+11] = elRequest.Result
argIdx += fieldCount
}
fmt.Fprint(&sql, EngineQuery(map[dbtypes.DBEngineType]string{
dbtypes.DBEnginePgsql: " ON CONFLICT (slot_root, slot_index) DO UPDATE SET orphaned = excluded.orphaned, tx_hash = excluded.tx_hash",
dbtypes.DBEnginePgsql: " ON CONFLICT (slot_root, slot_index) DO UPDATE SET orphaned = excluded.orphaned, tx_hash = excluded.tx_hash, result = excluded.result",
dbtypes.DBEngineSqlite: "",
}))

Expand All @@ -67,7 +68,7 @@ func GetWithdrawalRequestsFiltered(offset uint64, limit uint32, canonicalForkIds
fmt.Fprint(&sql, `
WITH cte AS (
SELECT
slot_number, slot_index, slot_root, orphaned, fork_id, source_address, validator_index, validator_pubkey, CAST(amount AS BIGINT), tx_hash, block_number
slot_number, slot_index, slot_root, orphaned, fork_id, source_address, validator_index, validator_pubkey, CAST(amount AS BIGINT), tx_hash, block_number, result
FROM withdrawal_requests
`)

Expand Down Expand Up @@ -159,7 +160,8 @@ func GetWithdrawalRequestsFiltered(offset uint64, limit uint32, canonicalForkIds
null AS validator_pubkey,
CAST(0 AS BIGINT) AS amount,
null AS tx_hash,
0 AS block_number
0 AS block_number,
0 AS result
FROM cte
UNION ALL SELECT * FROM (
SELECT * FROM cte
Expand Down
44 changes: 44 additions & 0 deletions dbtypes/dbtypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,30 @@ type Slashing struct {
ForkId uint64 `db:"fork_id"`
}

const (
ConsolidationRequestResultUnknown uint8 = 0
ConsolidationRequestResultSuccess uint8 = 1

// global errors
ConsolidationRequestResultTotalBalanceTooLow uint8 = 10
ConsolidationRequestResultQueueFull uint8 = 11

// source validator errors
ConsolidationRequestResultSrcNotFound uint8 = 20
ConsolidationRequestResultSrcInvalidCredentials uint8 = 21
ConsolidationRequestResultSrcInvalidSender uint8 = 22
ConsolidationRequestResultSrcNotActive uint8 = 23
ConsolidationRequestResultSrcNotOldEnough uint8 = 24
ConsolidationRequestResultSrcHasPendingWithdrawal uint8 = 25

// target validator errors
ConsolidationRequestResultTgtNotFound uint8 = 30
ConsolidationRequestResultTgtInvalidCredentials uint8 = 31
ConsolidationRequestResultTgtInvalidSender uint8 = 32
ConsolidationRequestResultTgtNotCompounding uint8 = 33
ConsolidationRequestResultTgtNotActive uint8 = 34
)

type ConsolidationRequest struct {
SlotNumber uint64 `db:"slot_number"`
SlotRoot []byte `db:"slot_root"`
Expand All @@ -264,6 +288,7 @@ type ConsolidationRequest struct {
TargetPubkey []byte `db:"target_pubkey"`
TxHash []byte `db:"tx_hash"`
BlockNumber uint64 `db:"block_number"`
Result uint8 `db:"result"`
}

type ConsolidationRequestTx struct {
Expand All @@ -283,6 +308,24 @@ type ConsolidationRequestTx struct {
DequeueBlock uint64 `db:"dequeue_block"`
}

const (
WithdrawalRequestResultUnknown uint8 = 0
WithdrawalRequestResultSuccess uint8 = 1

// global errors
WithdrawalRequestResultQueueFull uint8 = 10

// validator errors
WithdrawalRequestResultValidatorNotFound uint8 = 20
WithdrawalRequestResultValidatorInvalidCredentials uint8 = 21
WithdrawalRequestResultValidatorInvalidSender uint8 = 22
WithdrawalRequestResultValidatorNotActive uint8 = 23
WithdrawalRequestResultValidatorNotOldEnough uint8 = 24
WithdrawalRequestResultValidatorNotCompounding uint8 = 25
WithdrawalRequestResultValidatorHasPendingWithdrawal uint8 = 26
WithdrawalRequestResultValidatorBalanceTooLow uint8 = 27
)

type WithdrawalRequest struct {
SlotNumber uint64 `db:"slot_number"`
SlotRoot []byte `db:"slot_root"`
Expand All @@ -295,6 +338,7 @@ type WithdrawalRequest struct {
Amount int64 `db:"amount"`
TxHash []byte `db:"tx_hash"`
BlockNumber uint64 `db:"block_number"`
Result uint8 `db:"result"`
}

type WithdrawalRequestTx struct {
Expand Down
Loading

0 comments on commit d0788d5

Please sign in to comment.