diff --git a/Makefile b/Makefile index 78decfa95d..fdafc740f0 100644 --- a/Makefile +++ b/Makefile @@ -163,7 +163,7 @@ ALWAYS: # build our fork of libsodium, placing artifacts into crypto/lib/ and crypto/include/ crypto/libs/$(OS_TYPE)/$(ARCH)/lib/libsodium.a: mkdir -p crypto/copies/$(OS_TYPE)/$(ARCH) - cp -R crypto/libsodium-fork crypto/copies/$(OS_TYPE)/$(ARCH)/libsodium-fork + cp -R crypto/libsodium-fork/. crypto/copies/$(OS_TYPE)/$(ARCH)/libsodium-fork cd crypto/copies/$(OS_TYPE)/$(ARCH)/libsodium-fork && \ ./autogen.sh --prefix $(SRCPATH)/crypto/libs/$(OS_TYPE)/$(ARCH) && \ ./configure --disable-shared --prefix="$(SRCPATH)/crypto/libs/$(OS_TYPE)/$(ARCH)" && \ diff --git a/data/ledger_test.go b/data/ledger_test.go index 20a0828397..cd7d6297a0 100644 --- a/data/ledger_test.go +++ b/data/ledger_test.go @@ -19,6 +19,9 @@ package data import ( "context" "fmt" + "regexp" + "strconv" + "strings" "sync" "testing" @@ -625,10 +628,52 @@ func TestLedgerErrorValidate(t *testing.T) { for more { select { case err := <-errChan: + if strings.Contains(err.Error(), "before dbRound") { + // handle race eval errors like "round 1933 before dbRound 1934" + // see explanation in unexpectedMessages + re := regexp.MustCompile(`round (\d+) before dbRound (\d+)`) + result := re.FindStringSubmatch(err.Error()) + require.NotNil(t, result) + require.Len(t, result, 3) + evalRound, err1 := strconv.Atoi(result[1]) + require.NoError(t, err1) + dbRound, err1 := strconv.Atoi(result[2]) + require.NoError(t, err1) + require.GreaterOrEqual(t, int(l.Latest()), dbRound+int(cfg.MaxAcctLookback)) + require.Less(t, evalRound, dbRound) + err = nil + } require.NoError(t, err) case <-expectedMessages: // only debug messages should be reported case um := <-unexpectedMessages: + if strings.Contains(um, "before dbRound") { + // EnsureBlock might log the following: + // data.EnsureBlock: could not write block 774 to the ledger: round 773 before dbRound 774 + // it happens because of simultaneous EnsureValidatedBlock and EnsureBlock calls + // that pass round check and then EnsureBlock yields after StartEvaluator. + // Meanwhile EnsureValidatedBlock finishes and adds the block to the ledger. + // After that trackersDB commit happen and account data get flushed. + // The EnsureBlock goroutine then tries to evaluate a first transaction and fails because + // the trackerDB advanced further. + // This is okay to ignore if + // - attempted round is less or equal than dbRound + // - ledger latest round is greater than dbRound + cfg.MaxAcctLookback + re := regexp.MustCompile(`could not write block (\d+) to the ledger: round (\d+) before dbRound (\d+)`) + result := re.FindStringSubmatch(um) + require.NotNil(t, result) + require.Len(t, result, 4) + attemptedRound, err := strconv.Atoi(result[1]) + require.NoError(t, err) + evalRound, err := strconv.Atoi(result[2]) + require.NoError(t, err) + dbRound, err := strconv.Atoi(result[3]) + require.NoError(t, err) + require.Equal(t, attemptedRound, evalRound+1) + require.LessOrEqual(t, attemptedRound, dbRound) + require.GreaterOrEqual(t, int(l.Latest()), dbRound+int(cfg.MaxAcctLookback)) + um = "" + } require.Empty(t, um, um) default: more = false diff --git a/tools/network/dnssec/sort_test.go b/tools/network/dnssec/sort_test.go index ab1be21fbc..f84ed118d3 100644 --- a/tools/network/dnssec/sort_test.go +++ b/tools/network/dnssec/sort_test.go @@ -32,14 +32,26 @@ func TestSrvSort(t *testing.T) { arr := make([]*net.SRV, 0, 7) arr = append(arr, &net.SRV{Priority: 4, Weight: 1}) arr = append(arr, &net.SRV{Priority: 3, Weight: 1}) - arr = append(arr, &net.SRV{Priority: 1, Weight: 200}) + arr = append(arr, &net.SRV{Priority: 1, Weight: 0xFFFF}) // max possible value to increase the ordering probability arr = append(arr, &net.SRV{Priority: 1, Weight: 1}) arr = append(arr, &net.SRV{Priority: 1, Weight: 1}) arr = append(arr, &net.SRV{Priority: 1, Weight: 1}) arr = append(arr, &net.SRV{Priority: 1, Weight: 1}) + retryCounter := 0 +retry: srvRecArray(arr).sortAndRand() - a.Equal(net.SRV{Priority: 1, Weight: 200}, *arr[0]) + if (*arr[0] != net.SRV{Priority: 1, Weight: 0xFFFF}) { + // there is a small chance that a random number from 0 to max uint15 would be 0 or 1 + // in this case the first element of the resulting sequence would be with weight of 1 and not the highest possible. + // if this happens, we will try again since it is expected time to time. + if retryCounter > 1 { + a.Fail("The first element of the resulting sequence should be with the highest possible weight at least in one of 3 attempts") + } + retryCounter++ + goto retry + } + a.Equal(net.SRV{Priority: 1, Weight: 0xFFFF}, *arr[0]) a.Equal(net.SRV{Priority: 1, Weight: 1}, *arr[1]) a.Equal(net.SRV{Priority: 1, Weight: 1}, *arr[2]) a.Equal(net.SRV{Priority: 1, Weight: 1}, *arr[3])