Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

request result simulation #236

Merged
merged 23 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
4a02d56
commit
pk910 Feb 7, 2025
390137d
Merge branch 'pk910/validators-in-db' into pk910/request-simulation
pk910 Feb 7, 2025
c238cba
commit
pk910 Feb 8, 2025
39c3761
show simulated request results on UI
pk910 Feb 8, 2025
fad9941
fix result simulation in synchronizer
pk910 Feb 8, 2025
faf6a86
Merge branch 'pk910/validators-in-db' into pk910/request-simulation
pk910 Feb 8, 2025
040084f
cache block operation results & clean up code
pk910 Feb 8, 2025
8adbcf0
fix table size for consolidations/withdrawals list
pk910 Feb 8, 2025
f30b64a
init controls on lazy loaded content
pk910 Feb 8, 2025
04164a5
show withdrawal request status on validator details page
pk910 Feb 8, 2025
c251d31
fix show additional withdrawal requests link on validator details page
pk910 Feb 8, 2025
e037a17
avoid incomplete spec warnings for non-scheduled forks
pk910 Feb 8, 2025
d20a4d3
fix state pullution from state simulator
pk910 Feb 9, 2025
aa2c4e2
avoid reusing cached simulation results for orphaned blocks on same slot
pk910 Feb 9, 2025
2468ba9
fix operation result error codes
pk910 Feb 9, 2025
60fb061
improve error messages
pk910 Feb 9, 2025
ac53118
fix schema upgrade for pgsql
pk910 Feb 13, 2025
54b1604
fix dequeue block calculation across multiple crawler calls (bad stat…
pk910 Feb 16, 2025
0d14a8e
Merge branch 'pk910/validators-in-db' into pk910/request-simulation
pk910 Feb 16, 2025
909d9d7
cleanup dead code
pk910 Feb 17, 2025
61d9eba
fix show more consolidations link
pk910 Feb 17, 2025
9a14c50
Merge branch 'master' into pk910/request-simulation
pk910 Feb 17, 2025
81f56df
Merge branch 'master' into pk910/request-simulation
pk910 Feb 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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