From 77aaa9fb65b97ee07bf4ceb15fae61912bcb24ab Mon Sep 17 00:00:00 2001 From: Rizeng Zheng Date: Fri, 11 Mar 2022 11:20:20 -0800 Subject: [PATCH] Include operations from related transactions to match intent --- pkg/processor/broadcast_storage_handler.go | 15 ++++++++++++++- pkg/tester/construction.go | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/pkg/processor/broadcast_storage_handler.go b/pkg/processor/broadcast_storage_handler.go index 57b881c3..32e617f9 100644 --- a/pkg/processor/broadcast_storage_handler.go +++ b/pkg/processor/broadcast_storage_handler.go @@ -35,6 +35,7 @@ var _ modules.BroadcastStorageHandler = (*BroadcastStorageHandler)(nil) // can be sent to other functions (ex: reconciler). type BroadcastStorageHandler struct { config *configuration.Configuration + blockStorage *modules.BlockStorage counterStorage *modules.CounterStorage coordinator *coordinator.Coordinator parser *parser.Parser @@ -43,12 +44,14 @@ type BroadcastStorageHandler struct { // NewBroadcastStorageHandler returns a new *BroadcastStorageHandler. func NewBroadcastStorageHandler( config *configuration.Configuration, + blockStorage *modules.BlockStorage, counterStorage *modules.CounterStorage, coordinator *coordinator.Coordinator, parser *parser.Parser, ) *BroadcastStorageHandler { return &BroadcastStorageHandler{ config: config, + blockStorage: blockStorage, counterStorage: counterStorage, coordinator: coordinator, parser: parser, @@ -65,7 +68,17 @@ func (h *BroadcastStorageHandler) TransactionConfirmed( transaction *types.Transaction, intent []*types.Operation, ) error { - if err := h.parser.ExpectedOperations(intent, transaction.Operations, false, true); err != nil { + _, _, relatedTransactions, err := h.blockStorage.FindRelatedTransactions(ctx, transaction.TransactionIdentifier, dbTx) + if err != nil { + return fmt.Errorf("%w: could not find related transactions", err) + } + + observed := transaction.Operations + for _, relatedTransaction := range relatedTransactions { + observed = append(observed, relatedTransaction.Operations...) + } + + if err := h.parser.ExpectedOperations(intent, observed, false, true); err != nil { return fmt.Errorf("%w: confirmed transaction did not match intent", err) } diff --git a/pkg/tester/construction.go b/pkg/tester/construction.go index 653b3570..9470f916 100644 --- a/pkg/tester/construction.go +++ b/pkg/tester/construction.go @@ -261,6 +261,7 @@ func InitializeConstruction( broadcastHandler := processor.NewBroadcastStorageHandler( config, + blockStorage, counterStorage, coordinator, parser,