From 4865fd303ac3624f3687b9a9ac2be2630a099bc6 Mon Sep 17 00:00:00 2001 From: Xiaying Peng Date: Wed, 24 Apr 2024 14:30:38 -0700 Subject: [PATCH 1/2] validate staking ops --- .gitignore | 2 ++ pkg/processor/broadcast_storage_handler.go | 24 +++++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 218fd2fa..0795dcbe 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ rosetta-cli bin/ +/.vscode +/cli-data diff --git a/pkg/processor/broadcast_storage_handler.go b/pkg/processor/broadcast_storage_handler.go index aad34491..7e85731b 100644 --- a/pkg/processor/broadcast_storage_handler.go +++ b/pkg/processor/broadcast_storage_handler.go @@ -31,6 +31,8 @@ import ( var _ modules.BroadcastStorageHandler = (*BroadcastStorageHandler)(nil) +var stakingOpsTypes = []string{"stake", "unstake", "withdraw", "restake"} + // BroadcastStorageHandler is invoked whenever a block is added // or removed from block storage so that balance changes // can be sent to other functions (ex: reconciler). @@ -81,7 +83,10 @@ func (h *BroadcastStorageHandler) TransactionConfirmed( } if err := h.parser.ExpectedOperations(intent, observed, false, true); err != nil { - return fmt.Errorf("confirmed transaction did not match intent: %w", err) + errMsg := fmt.Errorf("confirmed transaction did not match intent: %w", err) + if !isValidStakingOperation(intent, intentMetadata) { + return errMsg + } } // Validate destination memo if it's needed @@ -114,6 +119,23 @@ func (h *BroadcastStorageHandler) TransactionConfirmed( return nil } +func isValidStakingOperation(intent []*types.Operation, metadata map[string]interface{}) bool { + stakingOpsTypes := map[string]bool{ + "stake": true, + "unstake": true, + "withdraw": true, + "restake": true, + } + + if _, found := metadata["validator_src_address"]; found { + if len(intent) == 1 { + _, found := stakingOpsTypes[intent[0].Type] + return found + } + } + return false +} + // TransactionStale is called when a transaction has not yet been // seen on-chain and is considered stale. This occurs when // current block height - last broadcast > staleDepth. From 453eabcc59e5cf30ff6f73b4aba138286253c861 Mon Sep 17 00:00:00 2001 From: Xiaying Peng Date: Wed, 24 Apr 2024 14:40:52 -0700 Subject: [PATCH 2/2] Update broadcast_storage_handler.go --- pkg/processor/broadcast_storage_handler.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/pkg/processor/broadcast_storage_handler.go b/pkg/processor/broadcast_storage_handler.go index 7e85731b..0fc0b378 100644 --- a/pkg/processor/broadcast_storage_handler.go +++ b/pkg/processor/broadcast_storage_handler.go @@ -31,8 +31,6 @@ import ( var _ modules.BroadcastStorageHandler = (*BroadcastStorageHandler)(nil) -var stakingOpsTypes = []string{"stake", "unstake", "withdraw", "restake"} - // BroadcastStorageHandler is invoked whenever a block is added // or removed from block storage so that balance changes // can be sent to other functions (ex: reconciler).