From 47c5e6ad1b8c83590b3376e3aef340ed2990665e Mon Sep 17 00:00:00 2001 From: iurii Date: Thu, 9 Jan 2025 12:35:37 +0200 Subject: [PATCH] add missing HasBeaconMetadata check, rename HasBeaconMetadata to HasOnChainData, group share on-chain data into separate struct --- eth/eventhandler/handlers.go | 4 ++++ protocol/v2/types/ssvshare.go | 20 ++++++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/eth/eventhandler/handlers.go b/eth/eventhandler/handlers.go index dbbcc6a7c8..4aa867c385 100644 --- a/eth/eventhandler/handlers.go +++ b/eth/eventhandler/handlers.go @@ -488,6 +488,10 @@ func (eh *EventHandler) handleValidatorExited(txn basedb.Txn, event *contract.Co return nil, &MalformedEventError{Err: ErrShareBelongsToDifferentOwner} } + if !share.HasBeaconMetadata() { + return nil, nil + } + pk := phase0.BLSPubKey{} copy(pk[:], share.ValidatorPubKey[:]) diff --git a/protocol/v2/types/ssvshare.go b/protocol/v2/types/ssvshare.go index 0a7b1e2ff4..e6f9565696 100644 --- a/protocol/v2/types/ssvshare.go +++ b/protocol/v2/types/ssvshare.go @@ -24,7 +24,19 @@ const ( // SSVShare is a spectypes.Share with extra data that fully describes SSV validator share. type SSVShare struct { spectypes.Share + ShareOnChainData + // lastUpdated is used to keep track of share last update time. Note, we don't + // store this field in DB - it just serves as a helper-indicator for when we might want + // to update SSVShare data so it doesn't get super stale. + lastUpdated time.Time + + // committeeID is a cached value for committee ID so we don't recompute it every time. + committeeID atomic.Pointer[spectypes.CommitteeID] +} + +// ShareOnChainData is share-related data pulled from blockchain. +type ShareOnChainData struct { // Balance is validator (this share belongs to) balance. Balance phase0.Gwei // Status is validator (this share belongs to) state. @@ -35,14 +47,6 @@ type SSVShare struct { OwnerAddress common.Address // Liquidated is validator (this share belongs to) liquidation status (true or false). Liquidated bool - - // lastUpdated is used to keep track of share last update time. Note, we don't - // store this field in DB - it just serves as a helper-indicator for when we might want - // to update SSVShare data so it doesn't get super stale. - lastUpdated time.Time - - // committeeID is a cached value for committee ID so we don't recompute it every time. - committeeID atomic.Pointer[spectypes.CommitteeID] } // BelongsToOperator checks whether the share belongs to operator.