From 0b7b7e64295d40af8ea3f20ea4e2a044750b82ad Mon Sep 17 00:00:00 2001 From: Hang Su Date: Tue, 9 Aug 2022 13:50:34 -0400 Subject: [PATCH 1/2] holdup wait for bq to commit --- ledger/internal/eval_blackbox_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ledger/internal/eval_blackbox_test.go b/ledger/internal/eval_blackbox_test.go index 5a533ba8f7..8fc260d2ce 100644 --- a/ledger/internal/eval_blackbox_test.go +++ b/ledger/internal/eval_blackbox_test.go @@ -533,6 +533,8 @@ func endBlock(t testing.TB, ledger *ledger.Ledger, eval *internal.BlockEvaluator require.NoError(t, err) err = ledger.AddValidatedBlock(*validatedBlock, agreement.Certificate{}) require.NoError(t, err) + rndBQ := ledger.Latest() + ledger.WaitForCommit(rndBQ) return validatedBlock } From 01f78c9ae35ac2916474c0a8bbb062102a316197 Mon Sep 17 00:00:00 2001 From: Hang Su Date: Tue, 9 Aug 2022 15:23:45 -0400 Subject: [PATCH 2/2] comments to explain fix reason --- ledger/internal/eval_blackbox_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ledger/internal/eval_blackbox_test.go b/ledger/internal/eval_blackbox_test.go index 8fc260d2ce..11c51f9aa9 100644 --- a/ledger/internal/eval_blackbox_test.go +++ b/ledger/internal/eval_blackbox_test.go @@ -533,6 +533,14 @@ func endBlock(t testing.TB, ledger *ledger.Ledger, eval *internal.BlockEvaluator require.NoError(t, err) err = ledger.AddValidatedBlock(*validatedBlock, agreement.Certificate{}) require.NoError(t, err) + // `rndBQ` gives the latest known block round added to the ledger + // we should wait until `rndBQ` block to be committed to blockQueue, + // in case there is a data race, noted in + // https://github.com/algorand/go-algorand/issues/4349 + // where writing to `callTxnGroup` after `dl.fullBlock` caused data race, + // because the underlying async goroutine `go bq.syncer()` is reading `callTxnGroup`. + // A solution here would be wait until all new added blocks are committed, + // then we return the result and continue the execution. rndBQ := ledger.Latest() ledger.WaitForCommit(rndBQ) return validatedBlock