Skip to content

Commit

Permalink
Merge pull request #209 from gobitfly/NOBIDS/execution-deposits
Browse files Browse the repository at this point in the history
Nobids/execution deposits
  • Loading branch information
guybrush authored Apr 22, 2024
2 parents b65d6aa + c695099 commit 291b2d4
Show file tree
Hide file tree
Showing 9 changed files with 1,168 additions and 435 deletions.
1 change: 1 addition & 0 deletions backend/pkg/commons/contracts/deposit_contract/abi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes","name":"pubkey","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"withdrawal_credentials","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"amount","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"signature","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"index","type":"bytes"}],"name":"DepositEvent","type":"event"},{"inputs":[{"internalType":"bytes","name":"pubkey","type":"bytes"},{"internalType":"bytes","name":"withdrawal_credentials","type":"bytes"},{"internalType":"bytes","name":"signature","type":"bytes"},{"internalType":"bytes32","name":"deposit_data_root","type":"bytes32"}],"name":"deposit","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"get_deposit_count","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"get_deposit_root","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"}]
433 changes: 433 additions & 0 deletions backend/pkg/commons/contracts/deposit_contract/bindings.go

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
-- +goose Up
-- +goose StatementBegin

SELECT('up SQL query - add msg_sender, to_address, and log_index columns to eth1_deposits');
ALTER TABLE eth1_deposits ADD msg_sender bytea NULL;
ALTER TABLE eth1_deposits ADD to_address bytea NULL;
ALTER TABLE eth1_deposits ADD log_index int4 NULL;

SELECT('up SQL query - remove duplicate rows from eth1_deposits');
delete from
eth1_deposits
where
merkletree_index in (
select
merkletree_index
from
(
select
merkletree_index,
row_number() over (partition by merkletree_index) as rn,
COUNT(*) over (partition by merkletree_index) as cnt
from
eth1_deposits
) t
where
t.cnt > 1
);

SELECT('up SQL query - changing the primary key of eth1_deposits to be merkletree_index alone');
ALTER TABLE eth1_deposits DROP CONSTRAINT IF EXISTS eth1_deposits_pkey;
ALTER TABLE eth1_deposits ADD PRIMARY KEY (merkletree_index);

SELECT('up SQL query - add block_number index to eth1_deposits');
CREATE INDEX eth1_deposits_block_number_idx ON eth1_deposits (block_number);


-- +goose StatementEnd

-- +goose Down
-- +goose StatementBegin

SELECT('down SQL query - remove msg_sender, to_address, and log_index columns from eth1_deposits');
ALTER TABLE eth1_deposits DROP COLUMN msg_sender;
ALTER TABLE eth1_deposits DROP COLUMN to_address;
ALTER TABLE eth1_deposits DROP COLUMN log_index;

SELECT('down SQL query - changing the primary key of eth1_deposits back to be tx_hash & merkletree_index');
ALTER TABLE eth1_deposits DROP CONSTRAINT IF EXISTS eth1_deposits_pkey;
ALTER TABLE eth1_deposits ADD PRIMARY KEY (tx_hash, merkletree_index);

SELECT('down SQL query - remove block_number index from eth1_deposits');
DROP INDEX IF EXISTS eth1_deposits_block_number_idx;

-- +goose StatementEnd
5 changes: 3 additions & 2 deletions backend/pkg/commons/types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ type Config struct {
Type string `yaml:"type" envconfig:"INDEXER_NODE_TYPE"`
PageSize int32 `yaml:"pageSize" envconfig:"INDEXER_NODE_PAGE_SIZE"`
} `yaml:"node"`
Eth1DepositContractFirstBlock uint64 `yaml:"eth1DepositContractFirstBlock" envconfig:"INDEXER_ETH1_DEPOSIT_CONTRACT_FIRST_BLOCK"`
PubKeyTagsExporter struct {
ELDepositContractFirstBlock uint64 `yaml:"eth1DepositContractFirstBlock" envconfig:"INDEXER_ETH1_DEPOSIT_CONTRACT_FIRST_BLOCK"`
DoNotTraceDeposits bool `yaml:"doNotTraceDeposits" envconfig:"INDEXER_DO_NOT_TRACE_DEPOSITS"`
PubKeyTagsExporter struct {
Enabled bool `yaml:"enabled" envconfig:"PUBKEY_TAGS_EXPORTER_ENABLED"`
} `yaml:"pubkeyTagsExporter"`
EnsTransformer struct {
Expand Down
14 changes: 8 additions & 6 deletions backend/pkg/commons/types/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,15 +302,17 @@ type EpochAssignments struct {
SyncAssignments []uint64
}

// Eth1Deposit is a struct to hold eth1-deposit data
type Eth1Deposit struct {
// ELDeposit is a struct to hold execution layer deposit data
type ELDeposit struct {
TxHash []byte `db:"tx_hash"`
TxInput []byte `db:"tx_input"`
TxIndex uint64 `db:"tx_index"`
BlockNumber uint64 `db:"block_number"`
LogIndex uint64 `db:"log_index"`
BlockTs int64 `db:"block_ts"`
FromAddress []byte `db:"from_address"`
FromName string
FromAddressText string `db:"from_address_text"` // deprecated, TODO: remove
MsgSender []byte `db:"msg_sender"`
ToAddress []byte `db:"to_address"`
PublicKey []byte `db:"publickey"`
WithdrawalCredentials []byte `db:"withdrawal_credentials"`
Amount uint64 `db:"amount"`
Expand All @@ -320,8 +322,8 @@ type Eth1Deposit struct {
ValidSignature bool `db:"valid_signature"`
}

// Eth2Deposit is a struct to hold eth2-deposit data
type Eth2Deposit struct {
// CLDeposit is a struct to hold consensus layer deposit data
type CLDeposit struct {
BlockSlot uint64 `db:"block_slot"`
BlockIndex uint64 `db:"block_index"`
BlockRoot []byte `db:"block_root"`
Expand Down
4 changes: 2 additions & 2 deletions backend/pkg/commons/types/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -1141,9 +1141,9 @@ type EthTwoDepositData struct {
}

type ValidatorDeposits struct {
Eth1Deposits []Eth1Deposit
Eth1Deposits []ELDeposit
LastEth1DepositTs int64
Eth2Deposits []Eth2Deposit
Eth2Deposits []CLDeposit
}

type MyCryptoSignature struct {
Expand Down
12 changes: 6 additions & 6 deletions backend/pkg/exporter/modules/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ type ModuleInterface interface {
Init() error
GetName() string // Used for logging

// !Do not block in this functions for an extended period of time!
OnHead(*types.StandardEventHeadResponse) error
OnHead(*types.StandardEventHeadResponse) error // !Do not block in this functions for an extended period of time!
OnFinalizedCheckpoint(*types.StandardFinalizedCheckpointResponse) error
OnChainReorg(*types.StandardEventChainReorg) error
}
Expand All @@ -31,7 +30,6 @@ var Client *rpc.Client
func StartAll(context ModuleContext) {
if !utils.Config.JustV2 {
go networkLivenessUpdater(context.ConsClient)
go eth1DepositsExporter()
go genesisDepositsExporter(context.ConsClient)
go syncCommitteesExporter(context.ConsClient)
go syncCommitteesCountExporter()
Expand Down Expand Up @@ -65,10 +63,12 @@ func StartAll(context ModuleContext) {

modules := []ModuleInterface{}

if !utils.Config.JustV2 {
modules = append(modules, NewSlotExporter(context))
} else {
if utils.Config.JustV2 {
modules = append(modules, NewDashboardDataModule(context))
} else {
modules = append(modules,
NewSlotExporter(context),
NewExecutionDepositsExporter(context))
}

startSubscriptionModules(&context, modules)
Expand Down
Loading

0 comments on commit 291b2d4

Please sign in to comment.