From 74be81cf954a88863fe27e9ad1dc82e5146b48f3 Mon Sep 17 00:00:00 2001 From: Hang Su Date: Wed, 25 Jan 2023 14:48:31 -0500 Subject: [PATCH 01/31] init commit --- config/localTemplate.go | 6 +++++- ledger/lrukv_test.go | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/config/localTemplate.go b/config/localTemplate.go index 7caa5e9dee..01cb88bdee 100644 --- a/config/localTemplate.go +++ b/config/localTemplate.go @@ -41,7 +41,7 @@ type Local struct { // Version tracks the current version of the defaults so we can migrate old -> new // This is specifically important whenever we decide to change the default value // for an existing parameter. This field tag must be updated any time we add a new version. - Version uint32 `version[0]:"0" version[1]:"1" version[2]:"2" version[3]:"3" version[4]:"4" version[5]:"5" version[6]:"6" version[7]:"7" version[8]:"8" version[9]:"9" version[10]:"10" version[11]:"11" version[12]:"12" version[13]:"13" version[14]:"14" version[15]:"15" version[16]:"16" version[17]:"17" version[18]:"18" version[19]:"19" version[20]:"20" version[21]:"21" version[22]:"22" version[23]:"23" version[24]:"24" version[25]:"25" version[26]:"26" version[27]:"27"` + Version uint32 `version[0]:"0" version[1]:"1" version[2]:"2" version[3]:"3" version[4]:"4" version[5]:"5" version[6]:"6" version[7]:"7" version[8]:"8" version[9]:"9" version[10]:"10" version[11]:"11" version[12]:"12" version[13]:"13" version[14]:"14" version[15]:"15" version[16]:"16" version[17]:"17" version[18]:"18" version[19]:"19" version[20]:"20" version[21]:"21" version[22]:"22" version[23]:"23" version[24]:"24" version[25]:"25" version[26]:"26" version[27]:"27" version[28]:"28"` // environmental (may be overridden) // When enabled, stores blocks indefinitely, otherwise, only the most recent blocks @@ -490,6 +490,10 @@ type Local struct { // EnableExperimentalAPI enables experimental API endpoint. Note that these endpoints have no // guarantees in terms of functionality or future support. EnableExperimentalAPI bool `version[26]:"false"` + + // DisableLedgerLRUCache disables LRU caches in ledger for testing purpose. + // Note that we turn it on for only testing purpose, not supposed to use it in real production environment. + DisableLedgerLRUCache bool `version[28]:"false"` } // DNSBootstrapArray returns an array of one or more DNS Bootstrap identifiers diff --git a/ledger/lrukv_test.go b/ledger/lrukv_test.go index 18d0a47072..26b72245f7 100644 --- a/ledger/lrukv_test.go +++ b/ledger/lrukv_test.go @@ -80,6 +80,41 @@ func TestLRUBasicKV(t *testing.T) { } } +func TestLRUKVSize0(t *testing.T) { + partitiontest.PartitionTest(t) + + var baseKV lruKV + baseKV.init(logging.TestingLog(t), 0, 0) + + kvNum := 5 + + for i := 1; i <= kvNum; i++ { + go func(i int) { + time.Sleep(time.Duration((crypto.RandUint64() % 50)) * time.Millisecond) + kvValue := fmt.Sprintf("kv %d value", i) + kv := store.PersistedKVData{ + Value: []byte(kvValue), + Round: basics.Round(i), + } + baseKV.writePending(kv, fmt.Sprintf("key%d", i)) + }(i) + } + require.Empty(t, baseKV.pendingKVs) + baseKV.flushPendingWrites() + require.Empty(t, baseKV.kvs) + + for i := 0; i < kvNum; i++ { + kvValue := fmt.Sprintf("kv %d value", i) + kv := store.PersistedKVData{ + Value: []byte(kvValue), + Round: basics.Round(i), + } + baseKV.write(kv, fmt.Sprintf("key%d", i)) + } + + fmt.Println(baseKV.kvs) +} + func TestLRUKVPendingWrites(t *testing.T) { partitiontest.PartitionTest(t) From d616eb3878b2b0d1af264ce3b33613bb8405f85d Mon Sep 17 00:00:00 2001 From: Hang Su Date: Wed, 25 Jan 2023 15:00:19 -0500 Subject: [PATCH 02/31] disable option --- ledger/lruaccts.go | 6 ++++++ ledger/lrukv.go | 7 +++++++ ledger/lruonlineaccts.go | 6 ++++++ ledger/lruresources.go | 7 +++++++ 4 files changed, 26 insertions(+) diff --git a/ledger/lruaccts.go b/ledger/lruaccts.go index 22928012af..db37ffbe97 100644 --- a/ledger/lruaccts.go +++ b/ledger/lruaccts.go @@ -38,6 +38,8 @@ type lruAccounts struct { log logging.Logger // pendingWritesWarnThreshold is the threshold beyond we would write a warning for exceeding the number of pendingAccounts entries pendingWritesWarnThreshold int + // disableWriteAccounts is the boolean indicator that disables write into accounts + disableWriteAccounts bool pendingNotFound chan basics.Address notFound map[basics.Address]struct{} @@ -53,6 +55,7 @@ func (m *lruAccounts) init(log logging.Logger, pendingWrites int, pendingWritesW m.pendingNotFound = make(chan basics.Address, pendingWrites) m.log = log m.pendingWritesWarnThreshold = pendingWritesWarnThreshold + m.disableWriteAccounts = pendingWrites == 0 } // read the persistedAccountData object that the lruAccounts has for the given address. @@ -127,6 +130,9 @@ func (m *lruAccounts) writeNotFoundPending(addr basics.Address) { // to be promoted to the front of the list. // thread locking semantics : write lock func (m *lruAccounts) write(acctData store.PersistedAccountData) { + if m.disableWriteAccounts { + return + } if el := m.accounts[acctData.Addr]; el != nil { // already exists; is it a newer ? if el.Value.Before(&acctData) { diff --git a/ledger/lrukv.go b/ledger/lrukv.go index 77986eb1b6..703ca3dd2d 100644 --- a/ledger/lrukv.go +++ b/ledger/lrukv.go @@ -49,6 +49,9 @@ type lruKV struct { // pendingWritesWarnThreshold is the threshold beyond we would write a warning for exceeding the number of pendingKVs entries pendingWritesWarnThreshold int + + // disableWriteKV is the boolean indicator that disables write into kvs + disableWriteKV bool } // init initializes the lruKV for use. @@ -59,6 +62,7 @@ func (m *lruKV) init(log logging.Logger, pendingWrites int, pendingWritesWarnThr m.pendingKVs = make(chan cachedKVData, pendingWrites) m.log = log m.pendingWritesWarnThreshold = pendingWritesWarnThreshold + m.disableWriteKV = pendingWrites == 0 } // read the persistedKVData object that the lruKV has for the given key. @@ -103,6 +107,9 @@ func (m *lruKV) writePending(kv store.PersistedKVData, key string) { // to be promoted to the front of the list. // thread locking semantics : write lock func (m *lruKV) write(kvData store.PersistedKVData, key string) { + if m.disableWriteKV { + return + } if el := m.kvs[key]; el != nil { // already exists; is it a newer ? if el.Value.Before(&kvData) { diff --git a/ledger/lruonlineaccts.go b/ledger/lruonlineaccts.go index 35c8224d41..ddd0405157 100644 --- a/ledger/lruonlineaccts.go +++ b/ledger/lruonlineaccts.go @@ -38,6 +38,8 @@ type lruOnlineAccounts struct { log logging.Logger // pendingWritesWarnThreshold is the threshold beyond we would write a warning for exceeding the number of pendingAccounts entries pendingWritesWarnThreshold int + // disableWriteAccounts is the boolean indicator that disables write into accounts + disableWriteAccounts bool } // init initializes the lruAccounts for use. @@ -48,6 +50,7 @@ func (m *lruOnlineAccounts) init(log logging.Logger, pendingWrites int, pendingW m.pendingAccounts = make(chan store.PersistedOnlineAccountData, pendingWrites) m.log = log m.pendingWritesWarnThreshold = pendingWritesWarnThreshold + m.disableWriteAccounts = pendingWrites == 0 } // read the persistedAccountData object that the lruAccounts has for the given address. @@ -92,6 +95,9 @@ func (m *lruOnlineAccounts) writePending(acct store.PersistedOnlineAccountData) // to be promoted to the front of the list. // thread locking semantics : write lock func (m *lruOnlineAccounts) write(acctData store.PersistedOnlineAccountData) { + if m.disableWriteAccounts { + return + } if el := m.accounts[acctData.Addr]; el != nil { // already exists; is it a newer ? if el.Value.Before(&acctData) { diff --git a/ledger/lruresources.go b/ledger/lruresources.go index 222c1d6c07..4860ad5e34 100644 --- a/ledger/lruresources.go +++ b/ledger/lruresources.go @@ -50,6 +50,9 @@ type lruResources struct { // pendingWritesWarnThreshold is the threshold beyond we would write a warning for exceeding the number of pendingResources entries pendingWritesWarnThreshold int + // disableWriteResources is the boolean indicator that disables write into resources + disableWriteResources bool + pendingNotFound chan accountCreatable notFound map[accountCreatable]struct{} } @@ -64,6 +67,7 @@ func (m *lruResources) init(log logging.Logger, pendingWrites int, pendingWrites m.pendingNotFound = make(chan accountCreatable, pendingWrites) m.log = log m.pendingWritesWarnThreshold = pendingWritesWarnThreshold + m.disableWriteResources = pendingWrites == 0 } // read the persistedResourcesData object that the lruResources has for the given address and creatable index. @@ -149,6 +153,9 @@ func (m *lruResources) writeNotFoundPending(addr basics.Address, idx basics.Crea // to be promoted to the front of the list. // thread locking semantics : write lock func (m *lruResources) write(resData store.PersistedResourcesData, addr basics.Address) { + if m.disableWriteResources { + return + } if el := m.resources[accountCreatable{address: addr, index: resData.Aidx}]; el != nil { // already exists; is it a newer ? if el.Value.Before(&resData) { From 41274905fc5cfe6e2a2db9d8ed7b1f2775e823f3 Mon Sep 17 00:00:00 2001 From: Hang Su Date: Wed, 25 Jan 2023 15:07:49 -0500 Subject: [PATCH 03/31] disable option from config local to ledger --- ledger/acctonline.go | 10 +++++++++- ledger/acctupdates.go | 17 ++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/ledger/acctonline.go b/ledger/acctonline.go index f73b153e24..879409eae8 100644 --- a/ledger/acctonline.go +++ b/ledger/acctonline.go @@ -117,12 +117,16 @@ type onlineAccounts struct { // maxAcctLookback sets the minimim deltas size to keep in memory acctLookback uint64 + + // disableCache (de)activates the LRU cache use in onlineAccounts + disableCache bool } // initialize initializes the accountUpdates structure func (ao *onlineAccounts) initialize(cfg config.Local) { ao.accountsReadCond = sync.NewCond(ao.accountsMu.RLocker()) ao.acctLookback = cfg.MaxAcctLookback + ao.disableCache = cfg.DisableLedgerLRUCache } // loadFromDisk is the 2nd level initialization, and is required before the onlineAccounts becomes functional @@ -184,7 +188,11 @@ func (ao *onlineAccounts) initializeFromDisk(l ledgerForTracker, lastBalancesRou ao.accounts = make(map[basics.Address]modifiedOnlineAccount) ao.deltasAccum = []int{0} - ao.baseOnlineAccounts.init(ao.log, baseAccountsPendingAccountsBufferSize, baseAccountsPendingAccountsWarnThreshold) + if !ao.disableCache { + ao.baseOnlineAccounts.init(ao.log, baseAccountsPendingAccountsBufferSize, baseAccountsPendingAccountsWarnThreshold) + } else { + ao.baseOnlineAccounts.init(ao.log, 0, 0) + } return } diff --git a/ledger/acctupdates.go b/ledger/acctupdates.go index dbaaefca69..75dffcb614 100644 --- a/ledger/acctupdates.go +++ b/ledger/acctupdates.go @@ -227,6 +227,9 @@ type accountUpdates struct { // maxAcctLookback sets the minimim deltas size to keep in memory acctLookback uint64 + + // disableCache (de)activates the LRU cache use in accountUpdates + disableCache bool } // RoundOffsetError is an error for when requested round is behind earliest stored db entry @@ -296,6 +299,8 @@ func (au *accountUpdates) initialize(cfg config.Local) { // log metrics au.logAccountUpdatesMetrics = cfg.EnableAccountUpdatesStats au.logAccountUpdatesInterval = cfg.AccountUpdatesStatsInterval + + au.disableCache = cfg.DisableLedgerLRUCache } // loadFromDisk is the 2nd level initialization, and is required before the accountUpdates becomes functional @@ -962,9 +967,15 @@ func (au *accountUpdates) initializeFromDisk(l ledgerForTracker, lastBalancesRou au.creatables = make(map[basics.CreatableIndex]ledgercore.ModifiedCreatable) au.deltasAccum = []int{0} - au.baseAccounts.init(au.log, baseAccountsPendingAccountsBufferSize, baseAccountsPendingAccountsWarnThreshold) - au.baseResources.init(au.log, baseResourcesPendingAccountsBufferSize, baseResourcesPendingAccountsWarnThreshold) - au.baseKVs.init(au.log, baseKVPendingBufferSize, baseKVPendingWarnThreshold) + if !au.disableCache { + au.baseAccounts.init(au.log, baseAccountsPendingAccountsBufferSize, baseAccountsPendingAccountsWarnThreshold) + au.baseResources.init(au.log, baseResourcesPendingAccountsBufferSize, baseResourcesPendingAccountsWarnThreshold) + au.baseKVs.init(au.log, baseKVPendingBufferSize, baseKVPendingWarnThreshold) + } else { + au.baseAccounts.init(au.log, 0, 0) + au.baseResources.init(au.log, 0, 0) + au.baseKVs.init(au.log, 0, 0) + } return } From d0ad11aa594bc08d1e61e6dbf85b4d180585eda7 Mon Sep 17 00:00:00 2001 From: Hang Su Date: Wed, 25 Jan 2023 15:36:13 -0500 Subject: [PATCH 04/31] update a testcase for disabling lru cache in lrukv --- ledger/lrukv_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ledger/lrukv_test.go b/ledger/lrukv_test.go index 26b72245f7..2b380053b5 100644 --- a/ledger/lrukv_test.go +++ b/ledger/lrukv_test.go @@ -85,6 +85,7 @@ func TestLRUKVSize0(t *testing.T) { var baseKV lruKV baseKV.init(logging.TestingLog(t), 0, 0) + require.True(t, baseKV.disableWriteKV) kvNum := 5 @@ -112,7 +113,7 @@ func TestLRUKVSize0(t *testing.T) { baseKV.write(kv, fmt.Sprintf("key%d", i)) } - fmt.Println(baseKV.kvs) + require.Empty(t, baseKV.kvs) } func TestLRUKVPendingWrites(t *testing.T) { From 4e2e30e3170d938356c257bf64c04ffecd61af92 Mon Sep 17 00:00:00 2001 From: Hang Su Date: Wed, 25 Jan 2023 15:51:07 -0500 Subject: [PATCH 05/31] update config.json.example --- config/local_defaults.go | 3 +- installer/config.json.example | 3 +- test/testdata/configs/config-v28.json | 117 ++++++++++++++++++++++++++ 3 files changed, 121 insertions(+), 2 deletions(-) create mode 100644 test/testdata/configs/config-v28.json diff --git a/config/local_defaults.go b/config/local_defaults.go index 18604556f6..57db6c5d95 100644 --- a/config/local_defaults.go +++ b/config/local_defaults.go @@ -20,7 +20,7 @@ package config var defaultLocal = Local{ - Version: 27, + Version: 28, AccountUpdatesStatsInterval: 5000000000, AccountsRebuildSynchronousMode: 1, AgreementIncomingBundlesQueueLength: 15, @@ -49,6 +49,7 @@ var defaultLocal = Local{ DNSSecurityFlags: 1, DeadlockDetection: 0, DeadlockDetectionThreshold: 30, + DisableLedgerLRUCache: false, DisableLocalhostConnectionRateLimit: true, DisableNetworking: false, DisableOutgoingConnectionThrottling: false, diff --git a/installer/config.json.example b/installer/config.json.example index 137578e0fa..b17a15149c 100644 --- a/installer/config.json.example +++ b/installer/config.json.example @@ -1,5 +1,5 @@ { - "Version": 27, + "Version": 28, "AccountUpdatesStatsInterval": 5000000000, "AccountsRebuildSynchronousMode": 1, "AgreementIncomingBundlesQueueLength": 15, @@ -28,6 +28,7 @@ "DNSSecurityFlags": 1, "DeadlockDetection": 0, "DeadlockDetectionThreshold": 30, + "DisableLedgerLRUCache": false, "DisableLocalhostConnectionRateLimit": true, "DisableNetworking": false, "DisableOutgoingConnectionThrottling": false, diff --git a/test/testdata/configs/config-v28.json b/test/testdata/configs/config-v28.json new file mode 100644 index 0000000000..b17a15149c --- /dev/null +++ b/test/testdata/configs/config-v28.json @@ -0,0 +1,117 @@ +{ + "Version": 28, + "AccountUpdatesStatsInterval": 5000000000, + "AccountsRebuildSynchronousMode": 1, + "AgreementIncomingBundlesQueueLength": 15, + "AgreementIncomingProposalsQueueLength": 50, + "AgreementIncomingVotesQueueLength": 20000, + "AnnounceParticipationKey": true, + "Archival": false, + "BaseLoggerDebugLevel": 4, + "BlockServiceCustomFallbackEndpoints": "", + "BroadcastConnectionsLimit": -1, + "CadaverDirectory": "", + "CadaverSizeTarget": 0, + "CatchpointFileHistoryLength": 365, + "CatchpointInterval": 10000, + "CatchpointTracking": 0, + "CatchupBlockDownloadRetryAttempts": 1000, + "CatchupBlockValidateMode": 0, + "CatchupFailurePeerRefreshRate": 10, + "CatchupGossipBlockFetchTimeoutSec": 4, + "CatchupHTTPBlockFetchTimeoutSec": 4, + "CatchupLedgerDownloadRetryAttempts": 50, + "CatchupParallelBlocks": 16, + "ConnectionsRateLimitingCount": 60, + "ConnectionsRateLimitingWindowSeconds": 1, + "DNSBootstrapID": ".algorand.network", + "DNSSecurityFlags": 1, + "DeadlockDetection": 0, + "DeadlockDetectionThreshold": 30, + "DisableLedgerLRUCache": false, + "DisableLocalhostConnectionRateLimit": true, + "DisableNetworking": false, + "DisableOutgoingConnectionThrottling": false, + "EnableAccountUpdatesStats": false, + "EnableAgreementReporting": false, + "EnableAgreementTimeMetrics": false, + "EnableAssembleStats": false, + "EnableBlockService": false, + "EnableBlockServiceFallbackToArchiver": true, + "EnableCatchupFromArchiveServers": false, + "EnableDeveloperAPI": false, + "EnableExperimentalAPI": false, + "EnableGossipBlockService": true, + "EnableIncomingMessageFilter": false, + "EnableLedgerService": false, + "EnableMetricReporting": false, + "EnableOutgoingNetworkMessageFiltering": true, + "EnablePingHandler": true, + "EnableProcessBlockStats": false, + "EnableProfiler": false, + "EnableRequestLogger": false, + "EnableRuntimeMetrics": false, + "EnableTopAccountsReporting": false, + "EnableTxBacklogRateLimiting": false, + "EnableUsageLog": false, + "EnableVerbosedTransactionSyncLogging": false, + "EndpointAddress": "127.0.0.1:0", + "FallbackDNSResolverAddress": "", + "ForceFetchTransactions": false, + "ForceRelayMessages": false, + "GossipFanout": 4, + "HeartbeatUpdateInterval": 600, + "IncomingConnectionsLimit": 2400, + "IncomingMessageFilterBucketCount": 5, + "IncomingMessageFilterBucketSize": 512, + "IsIndexerActive": false, + "LedgerSynchronousMode": 2, + "LogArchiveMaxAge": "", + "LogArchiveName": "node.archive.log", + "LogSizeLimit": 1073741824, + "MaxAPIBoxPerApplication": 100000, + "MaxAPIResourcesPerAccount": 100000, + "MaxAcctLookback": 4, + "MaxCatchpointDownloadDuration": 7200000000000, + "MaxConnectionsPerIP": 15, + "MinCatchpointFileDownloadBytesPerSecond": 20480, + "NetAddress": "", + "NetworkMessageTraceServer": "", + "NetworkProtocolVersion": "", + "NodeExporterListenAddress": ":9100", + "NodeExporterPath": "./node_exporter", + "OptimizeAccountsDatabaseOnStartup": false, + "OutgoingMessageFilterBucketCount": 3, + "OutgoingMessageFilterBucketSize": 128, + "ParticipationKeysRefreshInterval": 60000000000, + "PeerConnectionsUpdateInterval": 3600, + "PeerPingPeriodSeconds": 0, + "PriorityPeers": {}, + "ProposalAssemblyTime": 500000000, + "PublicAddress": "", + "ReconnectTime": 60000000000, + "ReservedFDs": 256, + "RestConnectionsHardLimit": 2048, + "RestConnectionsSoftLimit": 1024, + "RestReadTimeoutSeconds": 15, + "RestWriteTimeoutSeconds": 120, + "RunHosted": false, + "SuggestedFeeBlockHistory": 3, + "SuggestedFeeSlidingWindowSize": 50, + "TLSCertFile": "", + "TLSKeyFile": "", + "TelemetryToLog": true, + "TransactionSyncDataExchangeRate": 0, + "TransactionSyncSignificantMessageThreshold": 0, + "TxBacklogReservedCapacityPerPeer": 20, + "TxBacklogServiceRateWindowSeconds": 10, + "TxBacklogSize": 26000, + "TxIncomingFilteringFlags": 1, + "TxPoolExponentialIncreaseFactor": 2, + "TxPoolSize": 75000, + "TxSyncIntervalSeconds": 60, + "TxSyncServeResponseSize": 1000000, + "TxSyncTimeoutSeconds": 30, + "UseXForwardedForAddressField": "", + "VerifiedTranscationsCacheSize": 150000 +} From a96a8fd08e6ae6e3eb5661e061ba682ab8a9ca93 Mon Sep 17 00:00:00 2001 From: Hang Su Date: Thu, 26 Jan 2023 14:39:43 -0500 Subject: [PATCH 06/31] more coverage from unit --- ledger/lruaccts_test.go | 36 ++++++++++++++++++++++++++++++ ledger/lrukv_test.go | 2 +- ledger/lruonlineaccts_test.go | 36 ++++++++++++++++++++++++++++++ ledger/lruresources_test.go | 42 +++++++++++++++++++++++++++++++++++ 4 files changed, 115 insertions(+), 1 deletion(-) diff --git a/ledger/lruaccts_test.go b/ledger/lruaccts_test.go index 625d40f3ea..d831028311 100644 --- a/ledger/lruaccts_test.go +++ b/ledger/lruaccts_test.go @@ -88,6 +88,42 @@ func TestLRUBasicAccounts(t *testing.T) { } } +func TestLRUAccountsDisable(t *testing.T) { + partitiontest.PartitionTest(t) + + var baseAcct lruAccounts + baseAcct.init(logging.TestingLog(t), 0, 0) + + accountsNum := 5 + + for i := 0; i < accountsNum; i++ { + go func(i int) { + time.Sleep(time.Duration((crypto.RandUint64() % 50)) * time.Millisecond) + acct := store.PersistedAccountData{ + Addr: basics.Address(crypto.Hash([]byte{byte(i)})), + Round: basics.Round(i), + Rowid: int64(i), + AccountData: store.BaseAccountData{MicroAlgos: basics.MicroAlgos{Raw: uint64(i)}}, + } + baseAcct.writePending(acct) + }(i) + } + require.Empty(t, baseAcct.pendingAccounts) + baseAcct.flushPendingWrites() + require.Empty(t, baseAcct.accounts) + + for i := 0; i < accountsNum; i++ { + acct := store.PersistedAccountData{ + Addr: basics.Address(crypto.Hash([]byte{byte(i)})), + Round: basics.Round(i), + Rowid: int64(i), + AccountData: store.BaseAccountData{MicroAlgos: basics.MicroAlgos{Raw: uint64(i)}}, + } + baseAcct.write(acct) + } + require.Empty(t, baseAcct.accounts) +} + func TestLRUAccountsPendingWrites(t *testing.T) { partitiontest.PartitionTest(t) diff --git a/ledger/lrukv_test.go b/ledger/lrukv_test.go index 2b380053b5..2797dd4b9a 100644 --- a/ledger/lrukv_test.go +++ b/ledger/lrukv_test.go @@ -80,7 +80,7 @@ func TestLRUBasicKV(t *testing.T) { } } -func TestLRUKVSize0(t *testing.T) { +func TestLRUKVDisable(t *testing.T) { partitiontest.PartitionTest(t) var baseKV lruKV diff --git a/ledger/lruonlineaccts_test.go b/ledger/lruonlineaccts_test.go index 0e0b314385..343c74558b 100644 --- a/ledger/lruonlineaccts_test.go +++ b/ledger/lruonlineaccts_test.go @@ -87,6 +87,42 @@ func TestLRUOnlineAccountsBasic(t *testing.T) { } } +func TestLRUOnlineAccountsDisable(t *testing.T) { + partitiontest.PartitionTest(t) + + var baseOnlineAcct lruOnlineAccounts + baseOnlineAcct.init(logging.TestingLog(t), 0, 0) + + accountsNum := 5 + + for i := 0; i < accountsNum; i++ { + go func(i int) { + time.Sleep(time.Duration((crypto.RandUint64() % 50)) * time.Millisecond) + acct := store.PersistedOnlineAccountData{ + Addr: basics.Address(crypto.Hash([]byte{byte(i)})), + Round: basics.Round(i), + Rowid: int64(i), + AccountData: store.BaseOnlineAccountData{MicroAlgos: basics.MicroAlgos{Raw: uint64(i)}}, + } + baseOnlineAcct.writePending(acct) + }(i) + } + require.Empty(t, baseOnlineAcct.pendingAccounts) + baseOnlineAcct.flushPendingWrites() + require.Empty(t, baseOnlineAcct.accounts) + + for i := 0; i < accountsNum; i++ { + acct := store.PersistedOnlineAccountData{ + Addr: basics.Address(crypto.Hash([]byte{byte(i)})), + Round: basics.Round(i), + Rowid: int64(i), + AccountData: store.BaseOnlineAccountData{MicroAlgos: basics.MicroAlgos{Raw: uint64(i)}}, + } + baseOnlineAcct.write(acct) + } + require.Empty(t, baseOnlineAcct.accounts) +} + func TestLRUOnlineAccountsPendingWrites(t *testing.T) { partitiontest.PartitionTest(t) diff --git a/ledger/lruresources_test.go b/ledger/lruresources_test.go index 6c97309031..8a61fbe823 100644 --- a/ledger/lruresources_test.go +++ b/ledger/lruresources_test.go @@ -89,6 +89,48 @@ func TestLRUBasicResources(t *testing.T) { } } +func TestLRUResourcesDisable(t *testing.T) { + partitiontest.PartitionTest(t) + + var baseRes lruResources + baseRes.init(logging.TestingLog(t), 0, 0) + + resourceNum := 5 + + for i := 1; i <= resourceNum; i++ { + go func(i int) { + time.Sleep(time.Duration((crypto.RandUint64() % 50)) * time.Millisecond) + addr := basics.Address(crypto.Hash([]byte{byte(i)})) + res := store.PersistedResourcesData{ + Addrid: int64(i), + Aidx: basics.CreatableIndex(i), + Round: basics.Round(i), + Data: store.ResourcesData{Total: uint64(i)}, + } + baseRes.writePending(res, addr) + baseRes.writeNotFoundPending(addr, basics.CreatableIndex(i)) + }(i) + } + require.Empty(t, baseRes.pendingResources) + require.Empty(t, baseRes.pendingNotFound) + baseRes.flushPendingWrites() + require.Empty(t, baseRes.resources) + require.Empty(t, baseRes.notFound) + + for i := 0; i < resourceNum; i++ { + addr := basics.Address(crypto.Hash([]byte{byte(i)})) + res := store.PersistedResourcesData{ + Addrid: int64(i), + Aidx: basics.CreatableIndex(i), + Round: basics.Round(i), + Data: store.ResourcesData{Total: uint64(i)}, + } + baseRes.write(res, addr) + } + + require.Empty(t, baseRes.resources) +} + func TestLRUResourcesPendingWrites(t *testing.T) { partitiontest.PartitionTest(t) From 1a8be9408da4c4b531db5cdb6b90b2dcd40f0671 Mon Sep 17 00:00:00 2001 From: Hang Su Date: Fri, 27 Jan 2023 12:30:48 -0500 Subject: [PATCH 07/31] attempting to run with cache on and cache off modes --- ledger/acctupdates_test.go | 43 ++++++++++-------- ledger/ledger_test.go | 89 ++++++++++++++++++++++++++++---------- 2 files changed, 91 insertions(+), 41 deletions(-) diff --git a/ledger/acctupdates_test.go b/ledger/acctupdates_test.go index 723e2c1986..2e56d662c1 100644 --- a/ledger/acctupdates_test.go +++ b/ledger/acctupdates_test.go @@ -475,12 +475,10 @@ func checkOnlineAcctUpdatesConsistency(t *testing.T, ao *onlineAccounts, rnd bas } } -func TestAcctUpdates(t *testing.T) { - partitiontest.PartitionTest(t) - - if runtime.GOARCH == "arm" || runtime.GOARCH == "arm64" { - t.Skip("This test is too slow on ARM and causes travis builds to time out") - } +func testAcctUpdates(t *testing.T, conf config.Local) { + //if runtime.GOARCH == "arm" || runtime.GOARCH == "arm64" { + // t.Skip("This test is too slow on ARM and causes travis builds to time out") + //} // The next operations are heavy on the memory. // Garbage collection helps prevent trashing @@ -488,7 +486,6 @@ func TestAcctUpdates(t *testing.T) { proto := config.Consensus[protocol.ConsensusCurrentVersion] - conf := config.GetDefaultLocal() for _, lookback := range []uint64{conf.MaxAcctLookback, proto.MaxBalLookback} { t.Run(fmt.Sprintf("lookback=%d", lookback), func(t *testing.T) { @@ -597,20 +594,24 @@ func TestAcctUpdates(t *testing.T) { } } -// TestAcctUpdatesFastUpdates tests catchpoint label writing datarace -func TestAcctUpdatesFastUpdates(t *testing.T) { +func TestAcctUpdates(t *testing.T) { partitiontest.PartitionTest(t) - if runtime.GOARCH == "arm" || runtime.GOARCH == "arm64" { - t.Skip("This test is too slow on ARM and causes travis builds to time out") - } + conf := config.GetDefaultLocal() + withOrWithoutLRUCache(t, conf, testAcctUpdates) +} + +// testAcctUpdatesFastUpdates tests catchpoint label writing datarace +func testAcctUpdatesFastUpdates(t *testing.T, conf config.Local) { + + //if runtime.GOARCH == "arm" || runtime.GOARCH == "arm64" { + // t.Skip("This test is too slow on ARM and causes travis builds to time out") + //} proto := config.Consensus[protocol.ConsensusCurrentVersion] accts := setupAccts(20) rewardsLevels := []uint64{0} - conf := config.GetDefaultLocal() - conf.CatchpointInterval = 1 initialBlocksCount := int(conf.MaxAcctLookback) ml := makeMockLedgerForTracker(t, true, initialBlocksCount, protocol.ConsensusCurrentVersion, accts) defer ml.Close() @@ -650,9 +651,7 @@ func TestAcctUpdatesFastUpdates(t *testing.T) { newAccts := applyPartialDeltas(accts[i-1], updates) blk := bookkeeping.Block{ - BlockHeader: bookkeeping.BlockHeader{ - Round: basics.Round(i), - }, + BlockHeader: bookkeeping.BlockHeader{Round: i}, } blk.RewardsLevel = rewardLevel blk.CurrentProtocol = protocol.ConsensusCurrentVersion @@ -673,6 +672,14 @@ func TestAcctUpdatesFastUpdates(t *testing.T) { wg.Wait() } +func TestAcctUpdatesFastUpdates(t *testing.T) { + partitiontest.PartitionTest(t) + + conf := config.GetDefaultLocal() + conf.CatchpointInterval = 1 + withOrWithoutLRUCache(t, conf, testAcctUpdatesFastUpdates) +} + func BenchmarkBalancesChanges(b *testing.B) { if runtime.GOARCH == "arm" || runtime.GOARCH == "arm64" { b.Skip("This test is too slow on ARM and causes travis builds to time out") @@ -876,7 +883,7 @@ func TestLargeAccountCountCatchpointGeneration(t *testing.T) { // The TestAcctUpdatesUpdatesCorrectness conduct a correctless test for the accounts update in the following way - // Each account is initialized with 100 algos. // On every round, each account move variable amount of funds to an accumulating account. -// The deltas for each accounts are picked by using the lookup method. +// The deltas for each account are picked by using the lookup method. // At the end of the test, we verify that each account has the expected amount of algos. // In addition, throughout the test, we check ( using lookup ) that the historical balances, *beyond* the // lookback are generating either an error, or returning the correct amount. diff --git a/ledger/ledger_test.go b/ledger/ledger_test.go index b9a1c64037..28c22546ba 100644 --- a/ledger/ledger_test.go +++ b/ledger/ledger_test.go @@ -197,19 +197,34 @@ func (l *Ledger) addBlockTxns(t *testing.T, accounts map[basics.Address]basics.A return l.AddBlock(blk, agreement.Certificate{}) } -func TestLedgerBasic(t *testing.T) { - partitiontest.PartitionTest(t) +func withOrWithoutLRUCache(t *testing.T, cfg config.Local, test func(t *testing.T, cfg config.Local)) { + cfg.DisableLedgerLRUCache = false + t.Run(fmt.Sprintf("test with lru cache"), func(t *testing.T) { + test(t, cfg) + }) + cfg.DisableLedgerLRUCache = true + t.Run(fmt.Sprintf("test without lru cache"), func(t *testing.T) { + test(t, cfg) + }) +} +func testLedgerBasic(t *testing.T, cfg config.Local) { genesisInitState, _ := ledgertesting.GenerateInitState(t, protocol.ConsensusCurrentVersion, 100) const inMem = true - cfg := config.GetDefaultLocal() - cfg.Archival = true log := logging.TestingLog(t) l, err := OpenLedger(log, t.Name(), inMem, genesisInitState, cfg) require.NoError(t, err, "could not open ledger") defer l.Close() } +func TestLedgerBasic(t *testing.T) { + partitiontest.PartitionTest(t) + cfg := config.GetDefaultLocal() + cfg.Archival = true + + withOrWithoutLRUCache(t, cfg, testLedgerBasic) +} + func TestLedgerBlockHeaders(t *testing.T) { partitiontest.PartitionTest(t) @@ -1503,14 +1518,10 @@ func triggerTrackerFlush(t *testing.T, l *Ledger, genesisInitState ledgercore.In l.trackers.waitAccountsWriting() } -func TestLedgerReload(t *testing.T) { - partitiontest.PartitionTest(t) - +func testLedgerReload(t *testing.T, cfg config.Local) { dbName := fmt.Sprintf("%s.%d", t.Name(), crypto.RandUint64()) genesisInitState := getInitState() const inMem = true - cfg := config.GetDefaultLocal() - cfg.Archival = true log := logging.TestingLog(t) log.SetLevel(logging.Info) l, err := OpenLedger(log, dbName, inMem, genesisInitState, cfg) @@ -1539,6 +1550,13 @@ func TestLedgerReload(t *testing.T) { } } +func TestLedgerReload(t *testing.T) { + partitiontest.PartitionTest(t) + cfg := config.GetDefaultLocal() + cfg.Archival = true + withOrWithoutLRUCache(t, cfg, testLedgerReload) +} + func TestWaitLedgerReload(t *testing.T) { partitiontest.PartitionTest(t) a := require.New(t) @@ -2883,17 +2901,13 @@ func verifyVotersContent(t *testing.T, expected map[basics.Round]*ledgercore.Vot } } -func TestVotersReloadFromDisk(t *testing.T) { - partitiontest.PartitionTest(t) - +func testVotersReloadFromDisk(t *testing.T, cfg config.Local) { proto := config.Consensus[protocol.ConsensusCurrentVersion] dbName := fmt.Sprintf("%s.%d", t.Name(), crypto.RandUint64()) genesisInitState := getInitState() genesisInitState.Block.CurrentProtocol = protocol.ConsensusCurrentVersion const inMem = true - cfg := config.GetDefaultLocal() - cfg.Archival = false - cfg.MaxAcctLookback = proto.StateProofInterval - proto.StateProofVotersLookback - 10 + log := logging.TestingLog(t) log.SetLevel(logging.Info) l, err := OpenLedger(log, dbName, inMem, genesisInitState, cfg) @@ -2931,17 +2945,26 @@ func TestVotersReloadFromDisk(t *testing.T) { verifyVotersContent(t, vtSnapshot, l.acctsOnline.voters.votersForRoundCache) } -func TestVotersReloadFromDiskAfterOneStateProofCommitted(t *testing.T) { +func TestVotersReloadFromDisk(t *testing.T) { partitiontest.PartitionTest(t) + + proto := config.Consensus[protocol.ConsensusCurrentVersion] + + cfg := config.GetDefaultLocal() + cfg.Archival = false + cfg.MaxAcctLookback = proto.StateProofInterval - proto.StateProofVotersLookback - 10 + + withOrWithoutLRUCache(t, cfg, testVotersReloadFromDisk) +} + +func testVotersReloadFromDiskAfterOneStateProofCommitted(t *testing.T, cfg config.Local) { proto := config.Consensus[protocol.ConsensusCurrentVersion] dbName := fmt.Sprintf("%s.%d", t.Name(), crypto.RandUint64()) genesisInitState := getInitState() genesisInitState.Block.CurrentProtocol = protocol.ConsensusCurrentVersion const inMem = true - cfg := config.GetDefaultLocal() - cfg.Archival = false - cfg.MaxAcctLookback = proto.StateProofInterval - proto.StateProofVotersLookback - 10 + log := logging.TestingLog(t) log.SetLevel(logging.Info) l, err := OpenLedger(log, dbName, inMem, genesisInitState, cfg) @@ -2991,17 +3014,25 @@ func TestVotersReloadFromDiskAfterOneStateProofCommitted(t *testing.T) { verifyVotersContent(t, vtSnapshot, l.acctsOnline.voters.votersForRoundCache) } -func TestVotersReloadFromDiskPassRecoveryPeriod(t *testing.T) { +func TestVotersReloadFromDiskAfterOneStateProofCommitted(t *testing.T) { partitiontest.PartitionTest(t) proto := config.Consensus[protocol.ConsensusCurrentVersion] + cfg := config.GetDefaultLocal() + cfg.Archival = false + cfg.MaxAcctLookback = proto.StateProofInterval - proto.StateProofVotersLookback - 10 + + withOrWithoutLRUCache(t, cfg, testVotersReloadFromDiskAfterOneStateProofCommitted) +} + +func testVotersReloadFromDiskPassRecoveryPeriod(t *testing.T, cfg config.Local) { + proto := config.Consensus[protocol.ConsensusCurrentVersion] + dbName := fmt.Sprintf("%s.%d", t.Name(), crypto.RandUint64()) genesisInitState := getInitState() genesisInitState.Block.CurrentProtocol = protocol.ConsensusCurrentVersion const inMem = true - cfg := config.GetDefaultLocal() - cfg.Archival = false - cfg.MaxAcctLookback = proto.StateProofInterval - proto.StateProofVotersLookback - 10 + log := logging.TestingLog(t) log.SetLevel(logging.Info) l, err := OpenLedger(log, dbName, inMem, genesisInitState, cfg) @@ -3052,3 +3083,15 @@ func TestVotersReloadFromDiskPassRecoveryPeriod(t *testing.T) { require.False(t, found) require.Equal(t, beforeRemoveVotersLen, len(l.acctsOnline.voters.votersForRoundCache)) } + +func TestVotersReloadFromDiskPassRecoveryPeriod(t *testing.T) { + partitiontest.PartitionTest(t) + + proto := config.Consensus[protocol.ConsensusCurrentVersion] + + cfg := config.GetDefaultLocal() + cfg.Archival = false + cfg.MaxAcctLookback = proto.StateProofInterval - proto.StateProofVotersLookback - 10 + + withOrWithoutLRUCache(t, cfg, testVotersReloadFromDiskPassRecoveryPeriod) +} From 280fb3ea8e8286417b910d85205b3f44913475a5 Mon Sep 17 00:00:00 2001 From: Hang Su Date: Fri, 27 Jan 2023 13:10:59 -0500 Subject: [PATCH 08/31] remove t skip in acctupdates_test.go --- ledger/acctupdates_test.go | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/ledger/acctupdates_test.go b/ledger/acctupdates_test.go index 2e56d662c1..8daa29ce1d 100644 --- a/ledger/acctupdates_test.go +++ b/ledger/acctupdates_test.go @@ -476,10 +476,6 @@ func checkOnlineAcctUpdatesConsistency(t *testing.T, ao *onlineAccounts, rnd bas } func testAcctUpdates(t *testing.T, conf config.Local) { - //if runtime.GOARCH == "arm" || runtime.GOARCH == "arm64" { - // t.Skip("This test is too slow on ARM and causes travis builds to time out") - //} - // The next operations are heavy on the memory. // Garbage collection helps prevent trashing runtime.GC() @@ -603,10 +599,6 @@ func TestAcctUpdates(t *testing.T) { // testAcctUpdatesFastUpdates tests catchpoint label writing datarace func testAcctUpdatesFastUpdates(t *testing.T, conf config.Local) { - - //if runtime.GOARCH == "arm" || runtime.GOARCH == "arm64" { - // t.Skip("This test is too slow on ARM and causes travis builds to time out") - //} proto := config.Consensus[protocol.ConsensusCurrentVersion] accts := setupAccts(20) @@ -799,9 +791,6 @@ func TestLargeAccountCountCatchpointGeneration(t *testing.T) { partitiontest.PartitionTest(t) t.Skip("TODO: move to catchpointtracker_test and add catchpoint tracker into trackers list") - if runtime.GOARCH == "arm" || runtime.GOARCH == "arm64" { - t.Skip("This test is too slow on ARM and causes travis builds to time out") - } // The next operations are heavy on the memory. // Garbage collection helps prevent trashing @@ -890,10 +879,6 @@ func TestLargeAccountCountCatchpointGeneration(t *testing.T) { func TestAcctUpdatesUpdatesCorrectness(t *testing.T) { partitiontest.PartitionTest(t) - if runtime.GOARCH == "arm" || runtime.GOARCH == "arm64" { - t.Skip("This test is too slow on ARM and causes travis builds to time out") - } - // create new protocol version, which has lower look back. testProtocolVersion := protocol.ConsensusCurrentVersion maxAcctLookback := config.GetDefaultLocal().MaxAcctLookback From 35639af9f16c2374feb10fc18a4652ccac0433b6 Mon Sep 17 00:00:00 2001 From: Hang Su Date: Fri, 27 Jan 2023 13:57:00 -0500 Subject: [PATCH 09/31] renaming withOrWithoutLRUCache to withAndWithoutLRUCache --- ledger/acctupdates_test.go | 4 ++-- ledger/ledger_test.go | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ledger/acctupdates_test.go b/ledger/acctupdates_test.go index 8daa29ce1d..b280143044 100644 --- a/ledger/acctupdates_test.go +++ b/ledger/acctupdates_test.go @@ -594,7 +594,7 @@ func TestAcctUpdates(t *testing.T) { partitiontest.PartitionTest(t) conf := config.GetDefaultLocal() - withOrWithoutLRUCache(t, conf, testAcctUpdates) + withAndWithoutLRUCache(t, conf, testAcctUpdates) } // testAcctUpdatesFastUpdates tests catchpoint label writing datarace @@ -669,7 +669,7 @@ func TestAcctUpdatesFastUpdates(t *testing.T) { conf := config.GetDefaultLocal() conf.CatchpointInterval = 1 - withOrWithoutLRUCache(t, conf, testAcctUpdatesFastUpdates) + withAndWithoutLRUCache(t, conf, testAcctUpdatesFastUpdates) } func BenchmarkBalancesChanges(b *testing.B) { diff --git a/ledger/ledger_test.go b/ledger/ledger_test.go index 28c22546ba..e56e3c9f57 100644 --- a/ledger/ledger_test.go +++ b/ledger/ledger_test.go @@ -197,7 +197,7 @@ func (l *Ledger) addBlockTxns(t *testing.T, accounts map[basics.Address]basics.A return l.AddBlock(blk, agreement.Certificate{}) } -func withOrWithoutLRUCache(t *testing.T, cfg config.Local, test func(t *testing.T, cfg config.Local)) { +func withAndWithoutLRUCache(t *testing.T, cfg config.Local, test func(t *testing.T, cfg config.Local)) { cfg.DisableLedgerLRUCache = false t.Run(fmt.Sprintf("test with lru cache"), func(t *testing.T) { test(t, cfg) @@ -222,7 +222,7 @@ func TestLedgerBasic(t *testing.T) { cfg := config.GetDefaultLocal() cfg.Archival = true - withOrWithoutLRUCache(t, cfg, testLedgerBasic) + withAndWithoutLRUCache(t, cfg, testLedgerBasic) } func TestLedgerBlockHeaders(t *testing.T) { @@ -1554,7 +1554,7 @@ func TestLedgerReload(t *testing.T) { partitiontest.PartitionTest(t) cfg := config.GetDefaultLocal() cfg.Archival = true - withOrWithoutLRUCache(t, cfg, testLedgerReload) + withAndWithoutLRUCache(t, cfg, testLedgerReload) } func TestWaitLedgerReload(t *testing.T) { @@ -2954,7 +2954,7 @@ func TestVotersReloadFromDisk(t *testing.T) { cfg.Archival = false cfg.MaxAcctLookback = proto.StateProofInterval - proto.StateProofVotersLookback - 10 - withOrWithoutLRUCache(t, cfg, testVotersReloadFromDisk) + withAndWithoutLRUCache(t, cfg, testVotersReloadFromDisk) } func testVotersReloadFromDiskAfterOneStateProofCommitted(t *testing.T, cfg config.Local) { @@ -3022,7 +3022,7 @@ func TestVotersReloadFromDiskAfterOneStateProofCommitted(t *testing.T) { cfg.Archival = false cfg.MaxAcctLookback = proto.StateProofInterval - proto.StateProofVotersLookback - 10 - withOrWithoutLRUCache(t, cfg, testVotersReloadFromDiskAfterOneStateProofCommitted) + withAndWithoutLRUCache(t, cfg, testVotersReloadFromDiskAfterOneStateProofCommitted) } func testVotersReloadFromDiskPassRecoveryPeriod(t *testing.T, cfg config.Local) { @@ -3093,5 +3093,5 @@ func TestVotersReloadFromDiskPassRecoveryPeriod(t *testing.T) { cfg.Archival = false cfg.MaxAcctLookback = proto.StateProofInterval - proto.StateProofVotersLookback - 10 - withOrWithoutLRUCache(t, cfg, testVotersReloadFromDiskPassRecoveryPeriod) + withAndWithoutLRUCache(t, cfg, testVotersReloadFromDiskPassRecoveryPeriod) } From c199c7f835dea80bcc155dd1d82feeaf0a2f66f1 Mon Sep 17 00:00:00 2001 From: Hang Su Date: Fri, 27 Jan 2023 13:59:57 -0500 Subject: [PATCH 10/31] poking around and set disable ledger lru cache to be true --- config/localTemplate.go | 2 +- config/local_defaults.go | 2 +- installer/config.json.example | 2 +- test/testdata/configs/config-v28.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/config/localTemplate.go b/config/localTemplate.go index 01cb88bdee..d72050d9d7 100644 --- a/config/localTemplate.go +++ b/config/localTemplate.go @@ -493,7 +493,7 @@ type Local struct { // DisableLedgerLRUCache disables LRU caches in ledger for testing purpose. // Note that we turn it on for only testing purpose, not supposed to use it in real production environment. - DisableLedgerLRUCache bool `version[28]:"false"` + DisableLedgerLRUCache bool `version[28]:"true"` } // DNSBootstrapArray returns an array of one or more DNS Bootstrap identifiers diff --git a/config/local_defaults.go b/config/local_defaults.go index 57db6c5d95..b1bc2ab9dc 100644 --- a/config/local_defaults.go +++ b/config/local_defaults.go @@ -49,7 +49,7 @@ var defaultLocal = Local{ DNSSecurityFlags: 1, DeadlockDetection: 0, DeadlockDetectionThreshold: 30, - DisableLedgerLRUCache: false, + DisableLedgerLRUCache: true, DisableLocalhostConnectionRateLimit: true, DisableNetworking: false, DisableOutgoingConnectionThrottling: false, diff --git a/installer/config.json.example b/installer/config.json.example index b17a15149c..86aeb7e9a7 100644 --- a/installer/config.json.example +++ b/installer/config.json.example @@ -28,7 +28,7 @@ "DNSSecurityFlags": 1, "DeadlockDetection": 0, "DeadlockDetectionThreshold": 30, - "DisableLedgerLRUCache": false, + "DisableLedgerLRUCache": true, "DisableLocalhostConnectionRateLimit": true, "DisableNetworking": false, "DisableOutgoingConnectionThrottling": false, diff --git a/test/testdata/configs/config-v28.json b/test/testdata/configs/config-v28.json index b17a15149c..86aeb7e9a7 100644 --- a/test/testdata/configs/config-v28.json +++ b/test/testdata/configs/config-v28.json @@ -28,7 +28,7 @@ "DNSSecurityFlags": 1, "DeadlockDetection": 0, "DeadlockDetectionThreshold": 30, - "DisableLedgerLRUCache": false, + "DisableLedgerLRUCache": true, "DisableLocalhostConnectionRateLimit": true, "DisableNetworking": false, "DisableOutgoingConnectionThrottling": false, From 4ef03ae06a6465cafaefaa392aacfc8d0a3493d6 Mon Sep 17 00:00:00 2001 From: Hang Su Date: Fri, 27 Jan 2023 15:01:36 -0500 Subject: [PATCH 11/31] higher warning threshold --- ledger/acctonline.go | 2 +- ledger/acctupdates.go | 6 +++--- ledger/archival_test.go | 8 -------- ledger/catchpointtracker_test.go | 4 ---- ledger/lruaccts_test.go | 2 +- ledger/lrukv_test.go | 2 +- ledger/lruonlineaccts_test.go | 2 +- ledger/lruresources_test.go | 2 +- 8 files changed, 8 insertions(+), 20 deletions(-) diff --git a/ledger/acctonline.go b/ledger/acctonline.go index 879409eae8..24dce14989 100644 --- a/ledger/acctonline.go +++ b/ledger/acctonline.go @@ -191,7 +191,7 @@ func (ao *onlineAccounts) initializeFromDisk(l ledgerForTracker, lastBalancesRou if !ao.disableCache { ao.baseOnlineAccounts.init(ao.log, baseAccountsPendingAccountsBufferSize, baseAccountsPendingAccountsWarnThreshold) } else { - ao.baseOnlineAccounts.init(ao.log, 0, 0) + ao.baseOnlineAccounts.init(ao.log, 0, 1) } return } diff --git a/ledger/acctupdates.go b/ledger/acctupdates.go index 75dffcb614..ba0b50b44c 100644 --- a/ledger/acctupdates.go +++ b/ledger/acctupdates.go @@ -972,9 +972,9 @@ func (au *accountUpdates) initializeFromDisk(l ledgerForTracker, lastBalancesRou au.baseResources.init(au.log, baseResourcesPendingAccountsBufferSize, baseResourcesPendingAccountsWarnThreshold) au.baseKVs.init(au.log, baseKVPendingBufferSize, baseKVPendingWarnThreshold) } else { - au.baseAccounts.init(au.log, 0, 0) - au.baseResources.init(au.log, 0, 0) - au.baseKVs.init(au.log, 0, 0) + au.baseAccounts.init(au.log, 0, 1) + au.baseResources.init(au.log, 0, 1) + au.baseKVs.init(au.log, 0, 1) } return } diff --git a/ledger/archival_test.go b/ledger/archival_test.go index c7f00b7d6a..7882eb27c9 100644 --- a/ledger/archival_test.go +++ b/ledger/archival_test.go @@ -129,14 +129,6 @@ func TestArchival(t *testing.T) { // // We generate mostly empty blocks, with the exception of timestamps, // which affect participationTracker.committedUpTo()'s return value. - - // This test was causing random crashes on travis when executed with the race detector - // due to memory exhustion. For the time being, I'm taking it offline from the ubuntu - // configuration where it used to cause failuires. - if runtime.GOOS == "linux" && runtime.GOARCH == "amd64" { - t.Skip("Skipping the TestArchival as it tend to randomally fail on travis linux-amd64") - } - dbName := fmt.Sprintf("%s.%d", t.Name(), crypto.RandUint64()) genesisInitState := getInitState() const inMem = true diff --git a/ledger/catchpointtracker_test.go b/ledger/catchpointtracker_test.go index 33cfe9baed..26b5143356 100644 --- a/ledger/catchpointtracker_test.go +++ b/ledger/catchpointtracker_test.go @@ -25,7 +25,6 @@ import ( "os" "path" "path/filepath" - "runtime" "strings" "sync/atomic" "testing" @@ -385,9 +384,6 @@ func BenchmarkLargeCatchpointDataWriting(b *testing.B) { func TestReproducibleCatchpointLabels(t *testing.T) { partitiontest.PartitionTest(t) - if runtime.GOARCH == "arm" || runtime.GOARCH == "arm64" { - t.Skip("This test is too slow on ARM and causes travis builds to time out") - } // create new protocol version, which has lower lookback testProtocolVersion := protocol.ConsensusVersion("test-protocol-TestReproducibleCatchpointLabels") protoParams := config.Consensus[protocol.ConsensusCurrentVersion] diff --git a/ledger/lruaccts_test.go b/ledger/lruaccts_test.go index d831028311..d5f8fdcab9 100644 --- a/ledger/lruaccts_test.go +++ b/ledger/lruaccts_test.go @@ -92,7 +92,7 @@ func TestLRUAccountsDisable(t *testing.T) { partitiontest.PartitionTest(t) var baseAcct lruAccounts - baseAcct.init(logging.TestingLog(t), 0, 0) + baseAcct.init(logging.TestingLog(t), 0, 1) accountsNum := 5 diff --git a/ledger/lrukv_test.go b/ledger/lrukv_test.go index 2797dd4b9a..e86703b4a2 100644 --- a/ledger/lrukv_test.go +++ b/ledger/lrukv_test.go @@ -84,7 +84,7 @@ func TestLRUKVDisable(t *testing.T) { partitiontest.PartitionTest(t) var baseKV lruKV - baseKV.init(logging.TestingLog(t), 0, 0) + baseKV.init(logging.TestingLog(t), 0, 1) require.True(t, baseKV.disableWriteKV) kvNum := 5 diff --git a/ledger/lruonlineaccts_test.go b/ledger/lruonlineaccts_test.go index 343c74558b..84acdb684e 100644 --- a/ledger/lruonlineaccts_test.go +++ b/ledger/lruonlineaccts_test.go @@ -91,7 +91,7 @@ func TestLRUOnlineAccountsDisable(t *testing.T) { partitiontest.PartitionTest(t) var baseOnlineAcct lruOnlineAccounts - baseOnlineAcct.init(logging.TestingLog(t), 0, 0) + baseOnlineAcct.init(logging.TestingLog(t), 0, 1) accountsNum := 5 diff --git a/ledger/lruresources_test.go b/ledger/lruresources_test.go index 8a61fbe823..8424fe2fe3 100644 --- a/ledger/lruresources_test.go +++ b/ledger/lruresources_test.go @@ -93,7 +93,7 @@ func TestLRUResourcesDisable(t *testing.T) { partitiontest.PartitionTest(t) var baseRes lruResources - baseRes.init(logging.TestingLog(t), 0, 0) + baseRes.init(logging.TestingLog(t), 0, 1) resourceNum := 5 From 7a5abd1f651c6f2f37e042b5e5522ac68834c173 Mon Sep 17 00:00:00 2001 From: Hang Su Date: Mon, 30 Jan 2023 10:14:30 -0500 Subject: [PATCH 12/31] codereading... --- ledger/ledger.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ledger/ledger.go b/ledger/ledger.go index cd023e5023..92332fae55 100644 --- a/ledger/ledger.go +++ b/ledger/ledger.go @@ -376,7 +376,7 @@ func initBlocksDB(tx *sql.Tx, l *Ledger, initBlocks []bookkeeping.Block, isArchi // Close reclaims resources used by the ledger (namely, the database connection // and goroutines used by trackers). func (l *Ledger) Close() { - // we shut the the blockqueue first, since it's sync goroutine dispatches calls + // we shut the blockqueue first, since it's sync goroutine dispatches calls // back to the trackers. if l.blockQ != nil { l.blockQ.stop() From e25556fdf70854b24b9610cecbcfbb35c955d5ea Mon Sep 17 00:00:00 2001 From: Hang Su Date: Mon, 30 Jan 2023 10:19:23 -0500 Subject: [PATCH 13/31] revert conflict commit --- config/localTemplate.go | 2 +- config/local_defaults.go | 2 +- installer/config.json.example | 2 +- test/testdata/configs/config-v28.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/config/localTemplate.go b/config/localTemplate.go index d72050d9d7..01cb88bdee 100644 --- a/config/localTemplate.go +++ b/config/localTemplate.go @@ -493,7 +493,7 @@ type Local struct { // DisableLedgerLRUCache disables LRU caches in ledger for testing purpose. // Note that we turn it on for only testing purpose, not supposed to use it in real production environment. - DisableLedgerLRUCache bool `version[28]:"true"` + DisableLedgerLRUCache bool `version[28]:"false"` } // DNSBootstrapArray returns an array of one or more DNS Bootstrap identifiers diff --git a/config/local_defaults.go b/config/local_defaults.go index b1bc2ab9dc..57db6c5d95 100644 --- a/config/local_defaults.go +++ b/config/local_defaults.go @@ -49,7 +49,7 @@ var defaultLocal = Local{ DNSSecurityFlags: 1, DeadlockDetection: 0, DeadlockDetectionThreshold: 30, - DisableLedgerLRUCache: true, + DisableLedgerLRUCache: false, DisableLocalhostConnectionRateLimit: true, DisableNetworking: false, DisableOutgoingConnectionThrottling: false, diff --git a/installer/config.json.example b/installer/config.json.example index 86aeb7e9a7..b17a15149c 100644 --- a/installer/config.json.example +++ b/installer/config.json.example @@ -28,7 +28,7 @@ "DNSSecurityFlags": 1, "DeadlockDetection": 0, "DeadlockDetectionThreshold": 30, - "DisableLedgerLRUCache": true, + "DisableLedgerLRUCache": false, "DisableLocalhostConnectionRateLimit": true, "DisableNetworking": false, "DisableOutgoingConnectionThrottling": false, diff --git a/test/testdata/configs/config-v28.json b/test/testdata/configs/config-v28.json index 86aeb7e9a7..b17a15149c 100644 --- a/test/testdata/configs/config-v28.json +++ b/test/testdata/configs/config-v28.json @@ -28,7 +28,7 @@ "DNSSecurityFlags": 1, "DeadlockDetection": 0, "DeadlockDetectionThreshold": 30, - "DisableLedgerLRUCache": true, + "DisableLedgerLRUCache": false, "DisableLocalhostConnectionRateLimit": true, "DisableNetworking": false, "DisableOutgoingConnectionThrottling": false, From aa7740e016223c9e0a61325d606c8f496fbfb6bf Mon Sep 17 00:00:00 2001 From: Hang Su Date: Mon, 30 Jan 2023 15:27:54 -0500 Subject: [PATCH 14/31] an ugly attempt to pass config.Local into TestConsensusRange --- ledger/apptxn_test.go | 93 ++++++++++++++++---------------- ledger/boxtxn_test.go | 30 +++++------ ledger/catchpointwriter_test.go | 9 ++-- ledger/double_test.go | 7 +-- ledger/eval_simple_test.go | 9 ++-- ledger/simple_test.go | 11 ++-- ledger/testing/consensusRange.go | 39 ++++++++------ ledger/txnbench_test.go | 5 +- 8 files changed, 108 insertions(+), 95 deletions(-) diff --git a/ledger/apptxn_test.go b/ledger/apptxn_test.go index a08a3b74b2..fa840b40a4 100644 --- a/ledger/apptxn_test.go +++ b/ledger/apptxn_test.go @@ -42,8 +42,8 @@ func TestPayAction(t *testing.T) { genBalances, addrs, _ := ledgertesting.NewTestGenesis() // Inner txns start in v30 - ledgertesting.TestConsensusRange(t, 30, 0, func(t *testing.T, ver int, cv protocol.ConsensusVersion) { - dl := NewDoubleLedger(t, genBalances, cv) + ledgertesting.TestConsensusRange(t, 30, 0, func(t *testing.T, ver int, cv protocol.ConsensusVersion, cfg config.Local) { + dl := NewDoubleLedger(t, genBalances, cv, cfg) defer dl.Close() ai := dl.fundedApp(addrs[0], 200000, // account min balance, plus fees @@ -159,7 +159,8 @@ func TestAxferAction(t *testing.T) { t.Parallel() genBalances, addrs, _ := ledgertesting.NewTestGenesis() - l := newSimpleLedgerWithConsensusVersion(t, genBalances, protocol.ConsensusFuture) + cfg := config.GetDefaultLocal() + l := newSimpleLedgerWithConsensusVersion(t, genBalances, protocol.ConsensusFuture, cfg) defer l.Close() asa := txntest.Txn{ @@ -1354,8 +1355,8 @@ func TestCreateAndUse(t *testing.T) { genBalances, addrs, _ := ledgertesting.NewTestGenesis() // At 30 the asset reference is illegal, then from v31 it works. - ledgertesting.TestConsensusRange(t, 30, 0, func(t *testing.T, ver int, cv protocol.ConsensusVersion) { - dl := NewDoubleLedger(t, genBalances, cv) + ledgertesting.TestConsensusRange(t, 30, 0, func(t *testing.T, ver int, cv protocol.ConsensusVersion, cfg config.Local) { + dl := NewDoubleLedger(t, genBalances, cv, cfg) defer dl.Close() createapp := txntest.Txn{ @@ -1424,8 +1425,8 @@ func TestGtxnEffects(t *testing.T) { genBalances, addrs, _ := ledgertesting.NewTestGenesis() // At 30 `gtxn CreatedAssetId is illegal, then from v31 it works. - ledgertesting.TestConsensusRange(t, 30, 0, func(t *testing.T, ver int, cv protocol.ConsensusVersion) { - dl := NewDoubleLedger(t, genBalances, cv) + ledgertesting.TestConsensusRange(t, 30, 0, func(t *testing.T, ver int, cv protocol.ConsensusVersion, cfg config.Local) { + dl := NewDoubleLedger(t, genBalances, cv, cfg) defer dl.Close() createapp := txntest.Txn{ @@ -1486,8 +1487,8 @@ func TestBasicReentry(t *testing.T) { t.Parallel() genBalances, addrs, _ := ledgertesting.NewTestGenesis() - ledgertesting.TestConsensusRange(t, 31, 0, func(t *testing.T, ver int, cv protocol.ConsensusVersion) { - dl := NewDoubleLedger(t, genBalances, cv) + ledgertesting.TestConsensusRange(t, 31, 0, func(t *testing.T, ver int, cv protocol.ConsensusVersion, cfg config.Local) { + dl := NewDoubleLedger(t, genBalances, cv, cfg) defer dl.Close() app0 := txntest.Txn{ @@ -1680,8 +1681,8 @@ func TestMaxInnerTxForSingleAppCall(t *testing.T) { genBalances, addrs, _ := ledgertesting.NewTestGenesis() // v31 = inner appl - ledgertesting.TestConsensusRange(t, 31, 0, func(t *testing.T, ver int, cv protocol.ConsensusVersion) { - dl := NewDoubleLedger(t, genBalances, cv) + ledgertesting.TestConsensusRange(t, 31, 0, func(t *testing.T, ver int, cv protocol.ConsensusVersion, cfg config.Local) { + dl := NewDoubleLedger(t, genBalances, cv, cfg) defer dl.Close() program := ` @@ -1840,8 +1841,8 @@ func TestInnerAppVersionCalling(t *testing.T) { genBalances, addrs, _ := ledgertesting.NewTestGenesis() // 31 allowed inner appls. v34 lowered proto.MinInnerApplVersion - ledgertesting.TestConsensusRange(t, 31, 0, func(t *testing.T, ver int, cv protocol.ConsensusVersion) { - dl := NewDoubleLedger(t, genBalances, cv) + ledgertesting.TestConsensusRange(t, 31, 0, func(t *testing.T, ver int, cv protocol.ConsensusVersion, cfg config.Local) { + dl := NewDoubleLedger(t, genBalances, cv, cfg) defer dl.Close() three, err := logic.AssembleStringWithVersion("int 1", 3) @@ -2034,8 +2035,8 @@ func TestAppDowngrade(t *testing.T) { // Confirm that in old protocol version, downgrade is legal // Start at 28 because we want to v4 app to downgrade to v3 - ledgertesting.TestConsensusRange(t, 28, 30, func(t *testing.T, ver int, cv protocol.ConsensusVersion) { - dl := NewDoubleLedger(t, genBalances, cv) + ledgertesting.TestConsensusRange(t, 28, 30, func(t *testing.T, ver int, cv protocol.ConsensusVersion, cfg config.Local) { + dl := NewDoubleLedger(t, genBalances, cv, cfg) defer dl.Close() create := txntest.Txn{ @@ -2065,8 +2066,8 @@ func TestAppDowngrade(t *testing.T) { dl.fullBlock(&update) }) - ledgertesting.TestConsensusRange(t, 31, 0, func(t *testing.T, ver int, cv protocol.ConsensusVersion) { - dl := NewDoubleLedger(t, genBalances, cv) + ledgertesting.TestConsensusRange(t, 31, 0, func(t *testing.T, ver int, cv protocol.ConsensusVersion, cfg config.Local) { + dl := NewDoubleLedger(t, genBalances, cv, cfg) defer dl.Close() create := txntest.Txn{ @@ -2310,7 +2311,8 @@ func executeMegaContract(b *testing.B) { var cv protocol.ConsensusVersion = "temp test" config.Consensus[cv] = vTest - l := newSimpleLedgerWithConsensusVersion(b, genBalances, cv) + cfg := config.GetDefaultLocal() + l := newSimpleLedgerWithConsensusVersion(b, genBalances, cv, cfg) defer l.Close() defer delete(config.Consensus, cv) @@ -2736,7 +2738,8 @@ func TestClearStateInnerPay(t *testing.T) { t.Run(fmt.Sprintf("i=%d", i), func(t *testing.T) { genBalances, addrs, _ := ledgertesting.NewTestGenesis() - l := newSimpleLedgerWithConsensusVersion(t, genBalances, test.consensus) + cfg := config.GetDefaultLocal() + l := newSimpleLedgerWithConsensusVersion(t, genBalances, test.consensus, cfg) defer l.Close() app0 := txntest.Txn{ @@ -3056,8 +3059,8 @@ func TestForeignAppAccountsAccessible(t *testing.T) { partitiontest.PartitionTest(t) genBalances, addrs, _ := ledgertesting.NewTestGenesis() - ledgertesting.TestConsensusRange(t, 32, 0, func(t *testing.T, ver int, cv protocol.ConsensusVersion) { - dl := NewDoubleLedger(t, genBalances, cv) + ledgertesting.TestConsensusRange(t, 32, 0, func(t *testing.T, ver int, cv protocol.ConsensusVersion, cfg config.Local) { + dl := NewDoubleLedger(t, genBalances, cv, cfg) defer dl.Close() appA := txntest.Txn{ @@ -3122,8 +3125,8 @@ func TestForeignAppAccountsImmutable(t *testing.T) { partitiontest.PartitionTest(t) genBalances, addrs, _ := ledgertesting.NewTestGenesis() - ledgertesting.TestConsensusRange(t, 32, 0, func(t *testing.T, ver int, cv protocol.ConsensusVersion) { - dl := NewDoubleLedger(t, genBalances, cv) + ledgertesting.TestConsensusRange(t, 32, 0, func(t *testing.T, ver int, cv protocol.ConsensusVersion, cfg config.Local) { + dl := NewDoubleLedger(t, genBalances, cv, cfg) defer dl.Close() appA := txntest.Txn{ @@ -3176,8 +3179,8 @@ func TestForeignAppAccountsMutable(t *testing.T) { partitiontest.PartitionTest(t) genBalances, addrs, _ := ledgertesting.NewTestGenesis() - ledgertesting.TestConsensusRange(t, 32, 0, func(t *testing.T, ver int, cv protocol.ConsensusVersion) { - dl := NewDoubleLedger(t, genBalances, cv) + ledgertesting.TestConsensusRange(t, 32, 0, func(t *testing.T, ver int, cv protocol.ConsensusVersion, cfg config.Local) { + dl := NewDoubleLedger(t, genBalances, cv, cfg) defer dl.Close() appA := txntest.Txn{ @@ -3257,8 +3260,8 @@ func TestReloadWithTxns(t *testing.T) { partitiontest.PartitionTest(t) genBalances, addrs, _ := ledgertesting.NewTestGenesis() - ledgertesting.TestConsensusRange(t, 34, 0, func(t *testing.T, ver int, cv protocol.ConsensusVersion) { - dl := NewDoubleLedger(t, genBalances, cv) + ledgertesting.TestConsensusRange(t, 34, 0, func(t *testing.T, ver int, cv protocol.ConsensusVersion, cfg config.Local) { + dl := NewDoubleLedger(t, genBalances, cv, cfg) defer dl.Close() dl.fullBlock() // So that the `block` opcode has a block to inspect @@ -3286,8 +3289,8 @@ func TestEvalAppState(t *testing.T) { genBalances, addrs, _ := ledgertesting.NewTestGenesis() // v24 = apps - ledgertesting.TestConsensusRange(t, 24, 0, func(t *testing.T, ver int, cv protocol.ConsensusVersion) { - dl := NewDoubleLedger(t, genBalances, cv) + ledgertesting.TestConsensusRange(t, 24, 0, func(t *testing.T, ver int, cv protocol.ConsensusVersion, cfg config.Local) { + dl := NewDoubleLedger(t, genBalances, cv, cfg) defer dl.Close() appcall1 := txntest.Txn{ @@ -3338,8 +3341,8 @@ func TestGarbageClearState(t *testing.T) { genBalances, addrs, _ := ledgertesting.NewTestGenesis() // v24 = apps - ledgertesting.TestConsensusRange(t, 24, 0, func(t *testing.T, ver int, cv protocol.ConsensusVersion) { - dl := NewDoubleLedger(t, genBalances, cv) + ledgertesting.TestConsensusRange(t, 24, 0, func(t *testing.T, ver int, cv protocol.ConsensusVersion, cfg config.Local) { + dl := NewDoubleLedger(t, genBalances, cv, cfg) defer dl.Close() createTxn := txntest.Txn{ @@ -3362,8 +3365,8 @@ func TestRewardsInAD(t *testing.T) { genBalances, addrs, _ := ledgertesting.NewTestGenesis() // v15 put rewards into ApplyData - ledgertesting.TestConsensusRange(t, 11, 0, func(t *testing.T, ver int, cv protocol.ConsensusVersion) { - dl := NewDoubleLedger(t, genBalances, cv) + ledgertesting.TestConsensusRange(t, 11, 0, func(t *testing.T, ver int, cv protocol.ConsensusVersion, cfg config.Local) { + dl := NewDoubleLedger(t, genBalances, cv, cfg) defer dl.Close() payTxn := txntest.Txn{Type: protocol.PaymentTx, Sender: addrs[0], Receiver: addrs[1]} @@ -3411,8 +3414,8 @@ func TestDeleteNonExistantKeys(t *testing.T) { genBalances, addrs, _ := ledgertesting.NewTestGenesis() // AVM v2 (apps) - ledgertesting.TestConsensusRange(t, 24, 0, func(t *testing.T, ver int, cv protocol.ConsensusVersion) { - dl := NewDoubleLedger(t, genBalances, cv) + ledgertesting.TestConsensusRange(t, 24, 0, func(t *testing.T, ver int, cv protocol.ConsensusVersion, cfg config.Local) { + dl := NewDoubleLedger(t, genBalances, cv, cfg) defer dl.Close() const appID basics.AppIndex = 1 @@ -3452,8 +3455,8 @@ func TestDuplicates(t *testing.T) { t.Parallel() genBalances, addrs, _ := ledgertesting.NewTestGenesis() - ledgertesting.TestConsensusRange(t, 11, 0, func(t *testing.T, ver int, cv protocol.ConsensusVersion) { - dl := NewDoubleLedger(t, genBalances, cv) + ledgertesting.TestConsensusRange(t, 11, 0, func(t *testing.T, ver int, cv protocol.ConsensusVersion, cfg config.Local) { + dl := NewDoubleLedger(t, genBalances, cv, cfg) defer dl.Close() pay := txntest.Txn{ @@ -3488,8 +3491,8 @@ func TestHeaderAccess(t *testing.T) { genBalances, addrs, _ := ledgertesting.NewTestGenesis() // Added in v34 - ledgertesting.TestConsensusRange(t, 34, 0, func(t *testing.T, ver int, cv protocol.ConsensusVersion) { - dl := NewDoubleLedger(t, genBalances, cv) + ledgertesting.TestConsensusRange(t, 34, 0, func(t *testing.T, ver int, cv protocol.ConsensusVersion, cfg config.Local) { + dl := NewDoubleLedger(t, genBalances, cv, cfg) defer dl.Close() fvt := txntest.Txn{ @@ -3538,8 +3541,8 @@ func TestLogsInBlock(t *testing.T) { genBalances, addrs, _ := ledgertesting.NewTestGenesis() // Run tests from v30 onward - ledgertesting.TestConsensusRange(t, 30, 0, func(t *testing.T, ver int, cv protocol.ConsensusVersion) { - dl := NewDoubleLedger(t, genBalances, cv) + ledgertesting.TestConsensusRange(t, 30, 0, func(t *testing.T, ver int, cv protocol.ConsensusVersion, cfg config.Local) { + dl := NewDoubleLedger(t, genBalances, cv, cfg) defer dl.Close() createTxn := txntest.Txn{ @@ -3598,8 +3601,8 @@ func TestUnfundedSenders(t *testing.T) { genBalances, addrs, _ := ledgertesting.NewTestGenesis() - ledgertesting.TestConsensusRange(t, 24, 0, func(t *testing.T, ver int, cv protocol.ConsensusVersion) { - dl := NewDoubleLedger(t, genBalances, cv) + ledgertesting.TestConsensusRange(t, 24, 0, func(t *testing.T, ver int, cv protocol.ConsensusVersion, cfg config.Local) { + dl := NewDoubleLedger(t, genBalances, cv, cfg) defer dl.Close() asaIndex := basics.AssetIndex(1) @@ -3711,8 +3714,8 @@ func TestAppCallAppDuringInit(t *testing.T) { partitiontest.PartitionTest(t) genBalances, addrs, _ := ledgertesting.NewTestGenesis() - ledgertesting.TestConsensusRange(t, 31, 0, func(t *testing.T, ver int, cv protocol.ConsensusVersion) { - dl := NewDoubleLedger(t, genBalances, cv) + ledgertesting.TestConsensusRange(t, 31, 0, func(t *testing.T, ver int, cv protocol.ConsensusVersion, cfg config.Local) { + dl := NewDoubleLedger(t, genBalances, cv, cfg) defer dl.Close() approve := txntest.Txn{ diff --git a/ledger/boxtxn_test.go b/ledger/boxtxn_test.go index f9099a4f91..47291575bf 100644 --- a/ledger/boxtxn_test.go +++ b/ledger/boxtxn_test.go @@ -138,8 +138,8 @@ func TestBoxCreate(t *testing.T) { t.Parallel() genBalances, addrs, _ := ledgertesting.NewTestGenesis() - ledgertesting.TestConsensusRange(t, boxVersion, 0, func(t *testing.T, ver int, cv protocol.ConsensusVersion) { - dl := NewDoubleLedger(t, genBalances, cv) + ledgertesting.TestConsensusRange(t, boxVersion, 0, func(t *testing.T, ver int, cv protocol.ConsensusVersion, cfg config.Local) { + dl := NewDoubleLedger(t, genBalances, cv, cfg) defer dl.Close() // increment for a size 24 box with 4 letter name @@ -210,8 +210,8 @@ func TestBoxRecreate(t *testing.T) { t.Parallel() genBalances, addrs, _ := ledgertesting.NewTestGenesis() - ledgertesting.TestConsensusRange(t, boxVersion, 0, func(t *testing.T, ver int, cv protocol.ConsensusVersion) { - dl := NewDoubleLedger(t, genBalances, cv) + ledgertesting.TestConsensusRange(t, boxVersion, 0, func(t *testing.T, ver int, cv protocol.ConsensusVersion, cfg config.Local) { + dl := NewDoubleLedger(t, genBalances, cv, cfg) defer dl.Close() // increment for a size 4 box with 4 letter name @@ -261,14 +261,14 @@ func TestBoxCreateAvailability(t *testing.T) { t.Parallel() genBalances, addrs, _ := ledgertesting.NewTestGenesis() - ledgertesting.TestConsensusRange(t, boxVersion, 0, func(t *testing.T, ver int, cv protocol.ConsensusVersion) { - dl := NewDoubleLedger(t, genBalances, cv) + ledgertesting.TestConsensusRange(t, boxVersion, 0, func(t *testing.T, ver int, cv protocol.ConsensusVersion, cfg config.Local) { + dl := NewDoubleLedger(t, genBalances, cv, cfg) defer dl.Close() accessInCreate := txntest.Txn{ Type: "appl", Sender: addrs[0], - ApplicationID: 0, // This is a create + ApplicationID: 0, // This is an app-creation Boxes: []transactions.BoxRef{{Index: 0, Name: []byte("hello")}}, ApprovalProgram: ` byte "hello" @@ -366,9 +366,9 @@ func TestBoxRW(t *testing.T) { t.Parallel() genBalances, addrs, _ := ledgertesting.NewTestGenesis() - ledgertesting.TestConsensusRange(t, boxVersion, 0, func(t *testing.T, ver int, cv protocol.ConsensusVersion) { + ledgertesting.TestConsensusRange(t, boxVersion, 0, func(t *testing.T, ver int, cv protocol.ConsensusVersion, cfg config.Local) { t.Parallel() - dl := NewDoubleLedger(t, genBalances, cv) + dl := NewDoubleLedger(t, genBalances, cv, cfg) defer dl.Close() var bufNewLogger bytes.Buffer @@ -441,8 +441,8 @@ func TestBoxAccountData(t *testing.T) { } genBalances, addrs, _ := ledgertesting.NewTestGenesis() - ledgertesting.TestConsensusRange(t, boxVersion, 0, func(t *testing.T, ver int, cv protocol.ConsensusVersion) { - dl := NewDoubleLedger(t, genBalances, cv) + ledgertesting.TestConsensusRange(t, boxVersion, 0, func(t *testing.T, ver int, cv protocol.ConsensusVersion, cfg config.Local) { + dl := NewDoubleLedger(t, genBalances, cv, cfg) defer dl.Close() proto := config.Consensus[cv] @@ -529,8 +529,8 @@ func TestBoxIOBudgets(t *testing.T) { t.Parallel() genBalances, addrs, _ := ledgertesting.NewTestGenesis() - ledgertesting.TestConsensusRange(t, boxVersion, 0, func(t *testing.T, ver int, cv protocol.ConsensusVersion) { - dl := NewDoubleLedger(t, genBalances, cv) + ledgertesting.TestConsensusRange(t, boxVersion, 0, func(t *testing.T, ver int, cv protocol.ConsensusVersion, cfg config.Local) { + dl := NewDoubleLedger(t, genBalances, cv, cfg) defer dl.Close() appIndex := dl.fundedApp(addrs[0], 0, boxAppSource) @@ -593,8 +593,8 @@ func TestBoxInners(t *testing.T) { t.Parallel() genBalances, addrs, _ := ledgertesting.NewTestGenesis() - ledgertesting.TestConsensusRange(t, boxVersion, 0, func(t *testing.T, ver int, cv protocol.ConsensusVersion) { - dl := NewDoubleLedger(t, genBalances, cv) + ledgertesting.TestConsensusRange(t, boxVersion, 0, func(t *testing.T, ver int, cv protocol.ConsensusVersion, cfg config.Local) { + dl := NewDoubleLedger(t, genBalances, cv, cfg) defer dl.Close() // Advance the creatable counter, so we don't have very low app ids that diff --git a/ledger/catchpointwriter_test.go b/ledger/catchpointwriter_test.go index 478df2bb25..6f5b6c45e6 100644 --- a/ledger/catchpointwriter_test.go +++ b/ledger/catchpointwriter_test.go @@ -658,7 +658,8 @@ func TestExactAccountChunk(t *testing.T) { t.Parallel() genBalances, addrs, _ := ledgertesting.NewTestGenesis() - dl := NewDoubleLedger(t, genBalances, protocol.ConsensusFuture) + cfg := config.GetDefaultLocal() + dl := NewDoubleLedger(t, genBalances, protocol.ConsensusFuture, cfg) defer dl.Close() pay := txntest.Txn{ @@ -702,7 +703,8 @@ func TestCatchpointAfterTxns(t *testing.T) { t.Parallel() genBalances, addrs, _ := ledgertesting.NewTestGenesis() - dl := NewDoubleLedger(t, genBalances, protocol.ConsensusFuture) + cfg := config.GetDefaultLocal() + dl := NewDoubleLedger(t, genBalances, protocol.ConsensusFuture, cfg) defer dl.Close() boxApp := dl.fundedApp(addrs[1], 1_000_000, boxAppSource) @@ -805,7 +807,8 @@ func TestCatchpointAfterBoxTxns(t *testing.T) { t.Parallel() genBalances, addrs, _ := ledgertesting.NewTestGenesis() - dl := NewDoubleLedger(t, genBalances, protocol.ConsensusFuture) + cfg := config.GetDefaultLocal() + dl := NewDoubleLedger(t, genBalances, protocol.ConsensusFuture, cfg) defer dl.Close() boxApp := dl.fundedApp(addrs[1], 1_000_000, boxAppSource) diff --git a/ledger/double_test.go b/ledger/double_test.go index 9b4ca20f11..0ca088ff5a 100644 --- a/ledger/double_test.go +++ b/ledger/double_test.go @@ -17,6 +17,7 @@ package ledger import ( + "github.com/algorand/go-algorand/config" "testing" "github.com/algorand/go-algorand/data/basics" @@ -55,9 +56,9 @@ func (dl DoubleLedger) Close() { } // NewDoubleLedger creates a new DoubleLedger with the supplied balances and consensus version. -func NewDoubleLedger(t *testing.T, balances bookkeeping.GenesisBalances, cv protocol.ConsensusVersion) DoubleLedger { - g := newSimpleLedgerWithConsensusVersion(t, balances, cv) - v := newSimpleLedgerFull(t, balances, cv, g.GenesisHash()) +func NewDoubleLedger(t *testing.T, balances bookkeeping.GenesisBalances, cv protocol.ConsensusVersion, cfg config.Local) DoubleLedger { + g := newSimpleLedgerWithConsensusVersion(t, balances, cv, cfg) + v := newSimpleLedgerFull(t, balances, cv, g.GenesisHash(), cfg) return DoubleLedger{t, g, v, nil} } diff --git a/ledger/eval_simple_test.go b/ledger/eval_simple_test.go index 4a2317dc1a..c5c9354520 100644 --- a/ledger/eval_simple_test.go +++ b/ledger/eval_simple_test.go @@ -318,7 +318,8 @@ func TestRekeying(t *testing.T) { func testEvalAppPoolingGroup(t *testing.T, schema basics.StateSchema, approvalProgram string, consensusVersion protocol.ConsensusVersion) error { genBalances, addrs, _ := ledgertesting.NewTestGenesis() - l := newSimpleLedgerWithConsensusVersion(t, genBalances, consensusVersion) + cfg := config.GetDefaultLocal() + l := newSimpleLedgerWithConsensusVersion(t, genBalances, consensusVersion, cfg) defer l.Close() eval := nextBlock(t, l) @@ -403,7 +404,8 @@ func TestMinBalanceChanges(t *testing.T) { t.Parallel() genBalances, addrs, _ := ledgertesting.NewTestGenesis() - l := newSimpleLedgerWithConsensusVersion(t, genBalances, protocol.ConsensusCurrentVersion) + cfg := config.GetDefaultLocal() + l := newSimpleLedgerWithConsensusVersion(t, genBalances, protocol.ConsensusCurrentVersion, cfg) defer l.Close() createTxn := txntest.Txn{ @@ -481,7 +483,8 @@ func TestAppInsMinBalance(t *testing.T) { t.Parallel() genBalances, addrs, _ := ledgertesting.NewTestGenesis() - l := newSimpleLedgerWithConsensusVersion(t, genBalances, protocol.ConsensusV30) + cfg := config.GetDefaultLocal() + l := newSimpleLedgerWithConsensusVersion(t, genBalances, protocol.ConsensusV30, cfg) defer l.Close() const appid basics.AppIndex = 1 diff --git a/ledger/simple_test.go b/ledger/simple_test.go index e934e3f013..d4e44f0c3f 100644 --- a/ledger/simple_test.go +++ b/ledger/simple_test.go @@ -35,23 +35,18 @@ import ( "github.com/stretchr/testify/require" ) -func newSimpleLedger(t testing.TB, balances bookkeeping.GenesisBalances) *Ledger { - return newSimpleLedgerWithConsensusVersion(t, balances, protocol.ConsensusFuture) -} - -func newSimpleLedgerWithConsensusVersion(t testing.TB, balances bookkeeping.GenesisBalances, cv protocol.ConsensusVersion) *Ledger { +func newSimpleLedgerWithConsensusVersion(t testing.TB, balances bookkeeping.GenesisBalances, cv protocol.ConsensusVersion, cfg config.Local) *Ledger { var genHash crypto.Digest crypto.RandBytes(genHash[:]) - return newSimpleLedgerFull(t, balances, cv, genHash) + return newSimpleLedgerFull(t, balances, cv, genHash, cfg) } -func newSimpleLedgerFull(t testing.TB, balances bookkeeping.GenesisBalances, cv protocol.ConsensusVersion, genHash crypto.Digest) *Ledger { +func newSimpleLedgerFull(t testing.TB, balances bookkeeping.GenesisBalances, cv protocol.ConsensusVersion, genHash crypto.Digest, cfg config.Local) *Ledger { genBlock, err := bookkeeping.MakeGenesisBlock(cv, balances, "test", genHash) require.NoError(t, err) require.False(t, genBlock.FeeSink.IsZero()) require.False(t, genBlock.RewardsPool.IsZero()) dbName := fmt.Sprintf("%s.%d", t.Name(), crypto.RandUint64()) - cfg := config.GetDefaultLocal() cfg.Archival = true l, err := OpenLedger(logging.Base(), dbName, true, ledgercore.InitState{ Block: genBlock, diff --git a/ledger/testing/consensusRange.go b/ledger/testing/consensusRange.go index e96bcc7280..f4db606759 100644 --- a/ledger/testing/consensusRange.go +++ b/ledger/testing/consensusRange.go @@ -18,6 +18,7 @@ package testing import ( "fmt" + "github.com/algorand/go-algorand/config" "testing" "github.com/algorand/go-algorand/protocol" @@ -59,6 +60,16 @@ var consensusByNumber = []protocol.ConsensusVersion{ protocol.ConsensusFuture, } +func versionStringFromIndex(index int) string { + var version string + if index == len(consensusByNumber)-1 { + version = "vFuture" + } else { + version = fmt.Sprintf("v%d", index) + } + return version +} + // TestConsensusRange allows for running tests against a range of consensus // versions. Generally `start` will be the version that introduced the feature, // and `stop` will be 0 to indicate it should work right on up through vFuture. @@ -69,38 +80,34 @@ var consensusByNumber = []protocol.ConsensusVersion{ // created and inserted in consensusByNumber. At that point, your feature is // probably active in that version. (If it's being held in vFuture, just // increment your `start`.) -func TestConsensusRange(t *testing.T, start, stop int, test func(t *testing.T, ver int, cv protocol.ConsensusVersion)) { +func TestConsensusRange(t *testing.T, start, stop int, test func(t *testing.T, ver int, cv protocol.ConsensusVersion, cfg config.Local)) { if stop == 0 { // Treat 0 as "future" stop = len(consensusByNumber) - 1 } require.LessOrEqual(t, start, stop) + cfg := config.GetDefaultLocal() for i := start; i <= stop; i++ { - var version string - if i == len(consensusByNumber)-1 { - version = "vFuture" - } else { - version = fmt.Sprintf("v%d", i) - } + version := versionStringFromIndex(i) t.Run(fmt.Sprintf("cv=%s", version), func(t *testing.T) { - test(t, i, consensusByNumber[i]) + test(t, i, consensusByNumber[i], cfg) }) } + cfg.DisableLedgerLRUCache = true + t.Run(fmt.Sprintf("cv=%s without LRU cache", versionStringFromIndex(stop)), func(t *testing.T) { + test(t, stop, consensusByNumber[stop], cfg) + }) } // BenchConsensusRange is for getting benchmarks across consensus versions. -func BenchConsensusRange(b *testing.B, start, stop int, bench func(t *testing.B, ver int, cv protocol.ConsensusVersion)) { +func BenchConsensusRange(b *testing.B, start, stop int, bench func(t *testing.B, ver int, cv protocol.ConsensusVersion, cfg config.Local)) { if stop == 0 { // Treat 0 as "future" stop = len(consensusByNumber) - 1 } + cfg := config.GetDefaultLocal() for i := start; i <= stop; i++ { - var version string - if i == len(consensusByNumber)-1 { - version = "vFuture" - } else { - version = fmt.Sprintf("v%d", i) - } + version := versionStringFromIndex(i) b.Run(fmt.Sprintf("cv=%s", version), func(b *testing.B) { - bench(b, i, consensusByNumber[i]) + bench(b, i, consensusByNumber[i], cfg) }) } } diff --git a/ledger/txnbench_test.go b/ledger/txnbench_test.go index ddc7aeba99..db8ec4af9a 100644 --- a/ledger/txnbench_test.go +++ b/ledger/txnbench_test.go @@ -18,6 +18,7 @@ package ledger import ( "errors" + "github.com/algorand/go-algorand/config" "strconv" "strings" "testing" @@ -34,8 +35,8 @@ import ( // BenchmarkTxnTypes compares the execution time of various txn types func BenchmarkTxnTypes(b *testing.B) { genBalances, addrs, _ := ledgertesting.NewTestGenesis() - ledgertesting.BenchConsensusRange(b, 30, 0, func(b *testing.B, ver int, cv protocol.ConsensusVersion) { - l := newSimpleLedgerWithConsensusVersion(b, genBalances, cv) + ledgertesting.BenchConsensusRange(b, 30, 0, func(b *testing.B, ver int, cv protocol.ConsensusVersion, cfg config.Local) { + l := newSimpleLedgerWithConsensusVersion(b, genBalances, cv, cfg) defer l.Close() createasa := txntest.Txn{ From f5f2af3db9a9c3742d2960274265a30766e50db8 Mon Sep 17 00:00:00 2001 From: Hang Su Date: Tue, 31 Jan 2023 09:45:51 -0500 Subject: [PATCH 15/31] this is a bad commit, we need to revert later, trigger no-cache test --- ledger/acctupdates_test.go | 71 ++++++++++++++++++++++++++++++++++++++ ledger/store/sql.go | 2 ++ 2 files changed, 73 insertions(+) diff --git a/ledger/acctupdates_test.go b/ledger/acctupdates_test.go index b280143044..012567f6ca 100644 --- a/ledger/acctupdates_test.go +++ b/ledger/acctupdates_test.go @@ -1322,6 +1322,77 @@ func TestBoxNamesByAppIDs(t *testing.T) { } } +func TestBoxKVNoCache(t *testing.T) { + partitiontest.PartitionTest(t) + t.Parallel() + + ledgertesting.TestConsensusRange(t, boxVersion, 0, func(t *testing.T, ver int, cv protocol.ConsensusVersion, cfg config.Local) { + initialBlocksCount := 1 + accts := make(map[basics.Address]basics.AccountData) + + protoParams := config.Consensus[cv] + + ml := makeMockLedgerForTracker(t, true, initialBlocksCount, cv, + []map[basics.Address]basics.AccountData{accts}, + ) + defer ml.Close() + + au, _ := newAcctUpdates(t, ml, cfg) + defer au.close() + + knownCreatables := make(map[basics.CreatableIndex]bool) + opts := auNewBlockOpts{ledgercore.AccountDeltas{}, protocol.ConsensusCurrentVersion, protoParams, knownCreatables} + + currentRound := basics.Round(1) + + addKV2AU := func(appID basics.AppIndex, boxKey, boxValue []byte) { + boxChange := ledgercore.KvValueDelta{Data: boxValue} + auNewBlock(t, currentRound, au, accts, opts, map[string]ledgercore.KvValueDelta{ + apps.MakeBoxKey(uint64(appID), string(boxKey)): boxChange, + }) + auCommitSync(t, currentRound, au, ml) + + // ensure rounds + rnd := au.latest() + require.Equal(t, currentRound, rnd) + if uint64(currentRound) > cfg.MaxAcctLookback { + require.Equal(t, currentRound-basics.Round(cfg.MaxAcctLookback), au.cachedDBRound) + } else { + require.Equal(t, basics.Round(0), au.cachedDBRound) + } + currentRound++ + } + + readKey := func(appID basics.AppIndex, boxKey []byte) ([]byte, error) { + res, err := au.LookupKv(currentRound-1, apps.MakeBoxKey(uint64(appID), string(boxKey))) + return res, err + } + + testcases := []struct { + appID basics.AppIndex + boxKey []byte + boxValue []byte + }{ + {appID: 10, boxKey: []byte("alice"), boxValue: []byte("value-alice")}, + {appID: 20, boxKey: []byte("bob--"), boxValue: []byte("value-bob--")}, + {appID: 30, boxKey: []byte("carol"), boxValue: []byte("value-carol")}, + {appID: 40, boxKey: []byte("dave-"), boxValue: []byte("value-dave-")}, + {appID: 50, boxKey: []byte("frank"), boxValue: []byte("value-frank")}, + } + + addKV2AU(testcases[0].appID, testcases[0].boxKey, testcases[0].boxValue) + addKV2AU(testcases[1].appID, testcases[1].boxKey, testcases[1].boxValue) + addKV2AU(testcases[2].appID, testcases[2].boxKey, testcases[2].boxValue) + addKV2AU(testcases[3].appID, testcases[3].boxKey, testcases[3].boxValue) + val, err := readKey(testcases[0].appID, testcases[0].boxKey) + require.NoError(t, err) + require.Equal(t, testcases[0].boxValue, val) + addKV2AU(testcases[4].appID, testcases[4].boxKey, testcases[4].boxValue) + _, err = readKey(testcases[0].appID, testcases[0].boxKey) + require.NoError(t, err) + }) +} + func TestKVCache(t *testing.T) { partitiontest.PartitionTest(t) t.Parallel() diff --git a/ledger/store/sql.go b/ledger/store/sql.go index 42c1ebf8fe..dcf912feac 100644 --- a/ledger/store/sql.go +++ b/ledger/store/sql.go @@ -255,6 +255,8 @@ func (qs *accountsDbQueries) LookupKeyValue(key string) (pv PersistedKVData, err err = db.Retry(func() error { var rawkey []byte var val []byte + return fmt.Errorf("should error here") + // Cast to []byte to avoid interpretation as character string, see note in upsertKvPair err := qs.lookupKvPairStmt.QueryRow([]byte(key)).Scan(&pv.Round, &rawkey, &val) if err != nil { From 8755dd81f79823f3f3b5f8d44e221bf52b6207a8 Mon Sep 17 00:00:00 2001 From: Hang Su Date: Tue, 31 Jan 2023 16:16:19 -0500 Subject: [PATCH 16/31] Revert "this is a bad commit, we need to revert later, trigger no-cache test" This reverts commit f5f2af3db9a9c3742d2960274265a30766e50db8. --- ledger/acctupdates_test.go | 71 -------------------------------------- ledger/store/sql.go | 2 -- 2 files changed, 73 deletions(-) diff --git a/ledger/acctupdates_test.go b/ledger/acctupdates_test.go index 012567f6ca..b280143044 100644 --- a/ledger/acctupdates_test.go +++ b/ledger/acctupdates_test.go @@ -1322,77 +1322,6 @@ func TestBoxNamesByAppIDs(t *testing.T) { } } -func TestBoxKVNoCache(t *testing.T) { - partitiontest.PartitionTest(t) - t.Parallel() - - ledgertesting.TestConsensusRange(t, boxVersion, 0, func(t *testing.T, ver int, cv protocol.ConsensusVersion, cfg config.Local) { - initialBlocksCount := 1 - accts := make(map[basics.Address]basics.AccountData) - - protoParams := config.Consensus[cv] - - ml := makeMockLedgerForTracker(t, true, initialBlocksCount, cv, - []map[basics.Address]basics.AccountData{accts}, - ) - defer ml.Close() - - au, _ := newAcctUpdates(t, ml, cfg) - defer au.close() - - knownCreatables := make(map[basics.CreatableIndex]bool) - opts := auNewBlockOpts{ledgercore.AccountDeltas{}, protocol.ConsensusCurrentVersion, protoParams, knownCreatables} - - currentRound := basics.Round(1) - - addKV2AU := func(appID basics.AppIndex, boxKey, boxValue []byte) { - boxChange := ledgercore.KvValueDelta{Data: boxValue} - auNewBlock(t, currentRound, au, accts, opts, map[string]ledgercore.KvValueDelta{ - apps.MakeBoxKey(uint64(appID), string(boxKey)): boxChange, - }) - auCommitSync(t, currentRound, au, ml) - - // ensure rounds - rnd := au.latest() - require.Equal(t, currentRound, rnd) - if uint64(currentRound) > cfg.MaxAcctLookback { - require.Equal(t, currentRound-basics.Round(cfg.MaxAcctLookback), au.cachedDBRound) - } else { - require.Equal(t, basics.Round(0), au.cachedDBRound) - } - currentRound++ - } - - readKey := func(appID basics.AppIndex, boxKey []byte) ([]byte, error) { - res, err := au.LookupKv(currentRound-1, apps.MakeBoxKey(uint64(appID), string(boxKey))) - return res, err - } - - testcases := []struct { - appID basics.AppIndex - boxKey []byte - boxValue []byte - }{ - {appID: 10, boxKey: []byte("alice"), boxValue: []byte("value-alice")}, - {appID: 20, boxKey: []byte("bob--"), boxValue: []byte("value-bob--")}, - {appID: 30, boxKey: []byte("carol"), boxValue: []byte("value-carol")}, - {appID: 40, boxKey: []byte("dave-"), boxValue: []byte("value-dave-")}, - {appID: 50, boxKey: []byte("frank"), boxValue: []byte("value-frank")}, - } - - addKV2AU(testcases[0].appID, testcases[0].boxKey, testcases[0].boxValue) - addKV2AU(testcases[1].appID, testcases[1].boxKey, testcases[1].boxValue) - addKV2AU(testcases[2].appID, testcases[2].boxKey, testcases[2].boxValue) - addKV2AU(testcases[3].appID, testcases[3].boxKey, testcases[3].boxValue) - val, err := readKey(testcases[0].appID, testcases[0].boxKey) - require.NoError(t, err) - require.Equal(t, testcases[0].boxValue, val) - addKV2AU(testcases[4].appID, testcases[4].boxKey, testcases[4].boxValue) - _, err = readKey(testcases[0].appID, testcases[0].boxKey) - require.NoError(t, err) - }) -} - func TestKVCache(t *testing.T) { partitiontest.PartitionTest(t) t.Parallel() diff --git a/ledger/store/sql.go b/ledger/store/sql.go index dcf912feac..42c1ebf8fe 100644 --- a/ledger/store/sql.go +++ b/ledger/store/sql.go @@ -255,8 +255,6 @@ func (qs *accountsDbQueries) LookupKeyValue(key string) (pv PersistedKVData, err err = db.Retry(func() error { var rawkey []byte var val []byte - return fmt.Errorf("should error here") - // Cast to []byte to avoid interpretation as character string, see note in upsertKvPair err := qs.lookupKvPairStmt.QueryRow([]byte(key)).Scan(&pv.Round, &rawkey, &val) if err != nil { From 7332a07423fc66cdcbd67efd66fd2d317f2b94c5 Mon Sep 17 00:00:00 2001 From: Hang Su Date: Tue, 31 Jan 2023 16:44:41 -0500 Subject: [PATCH 17/31] minor testing --- ledger/double_test.go | 2 +- ledger/testing/consensusRange.go | 2 +- ledger/testing/consensusRange_test.go | 3 +++ ledger/txnbench_test.go | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/ledger/double_test.go b/ledger/double_test.go index 0ca088ff5a..bbc5e95206 100644 --- a/ledger/double_test.go +++ b/ledger/double_test.go @@ -17,9 +17,9 @@ package ledger import ( - "github.com/algorand/go-algorand/config" "testing" + "github.com/algorand/go-algorand/config" "github.com/algorand/go-algorand/data/basics" "github.com/algorand/go-algorand/data/bookkeeping" "github.com/algorand/go-algorand/data/transactions" diff --git a/ledger/testing/consensusRange.go b/ledger/testing/consensusRange.go index f4db606759..2f6e4c6139 100644 --- a/ledger/testing/consensusRange.go +++ b/ledger/testing/consensusRange.go @@ -18,9 +18,9 @@ package testing import ( "fmt" - "github.com/algorand/go-algorand/config" "testing" + "github.com/algorand/go-algorand/config" "github.com/algorand/go-algorand/protocol" "github.com/stretchr/testify/require" ) diff --git a/ledger/testing/consensusRange_test.go b/ledger/testing/consensusRange_test.go index 325373a396..cd5baaa817 100644 --- a/ledger/testing/consensusRange_test.go +++ b/ledger/testing/consensusRange_test.go @@ -55,4 +55,7 @@ func TestReleasedVersion(t *testing.T) { require.NotZero(t, params) // just making sure an empty one didn't get put in } + require.Equal(t, versionStringFromIndex(len(consensusByNumber)-1), "vFuture") + require.Equal(t, versionStringFromIndex(36), "v36") + } diff --git a/ledger/txnbench_test.go b/ledger/txnbench_test.go index db8ec4af9a..5679af8df2 100644 --- a/ledger/txnbench_test.go +++ b/ledger/txnbench_test.go @@ -18,11 +18,11 @@ package ledger import ( "errors" - "github.com/algorand/go-algorand/config" "strconv" "strings" "testing" + "github.com/algorand/go-algorand/config" "github.com/algorand/go-algorand/data/basics" "github.com/algorand/go-algorand/data/transactions" "github.com/algorand/go-algorand/data/txntest" From eccd71efe901f6905c35629499ef967b1991b9e1 Mon Sep 17 00:00:00 2001 From: Hang Su Date: Thu, 2 Feb 2023 16:48:23 -0500 Subject: [PATCH 18/31] per pr comment, local ver27, warning threshold 0 --- config/localTemplate.go | 4 +- installer/config.json.example | 2 +- ledger/acctonline.go | 2 +- ledger/acctupdates.go | 6 +- test/testdata/configs/config-v27.json | 1 + test/testdata/configs/config-v28.json | 117 -------------------------- 6 files changed, 8 insertions(+), 124 deletions(-) delete mode 100644 test/testdata/configs/config-v28.json diff --git a/config/localTemplate.go b/config/localTemplate.go index 6831544bac..04b4fb6faa 100644 --- a/config/localTemplate.go +++ b/config/localTemplate.go @@ -41,7 +41,7 @@ type Local struct { // Version tracks the current version of the defaults so we can migrate old -> new // This is specifically important whenever we decide to change the default value // for an existing parameter. This field tag must be updated any time we add a new version. - Version uint32 `version[0]:"0" version[1]:"1" version[2]:"2" version[3]:"3" version[4]:"4" version[5]:"5" version[6]:"6" version[7]:"7" version[8]:"8" version[9]:"9" version[10]:"10" version[11]:"11" version[12]:"12" version[13]:"13" version[14]:"14" version[15]:"15" version[16]:"16" version[17]:"17" version[18]:"18" version[19]:"19" version[20]:"20" version[21]:"21" version[22]:"22" version[23]:"23" version[24]:"24" version[25]:"25" version[26]:"26" version[27]:"27" version[28]:"28"` + Version uint32 `version[0]:"0" version[1]:"1" version[2]:"2" version[3]:"3" version[4]:"4" version[5]:"5" version[6]:"6" version[7]:"7" version[8]:"8" version[9]:"9" version[10]:"10" version[11]:"11" version[12]:"12" version[13]:"13" version[14]:"14" version[15]:"15" version[16]:"16" version[17]:"17" version[18]:"18" version[19]:"19" version[20]:"20" version[21]:"21" version[22]:"22" version[23]:"23" version[24]:"24" version[25]:"25" version[26]:"26" version[27]:"27"` // environmental (may be overridden) // When enabled, stores blocks indefinitely, otherwise, only the most recent blocks @@ -495,7 +495,7 @@ type Local struct { // DisableLedgerLRUCache disables LRU caches in ledger for testing purpose. // Note that we turn it on for only testing purpose, not supposed to use it in real production environment. - DisableLedgerLRUCache bool `version[28]:"false"` + DisableLedgerLRUCache bool `version[27]:"false"` // EnableFollowMode launches the node in "follower" mode. This turns off the agreement service, // and APIs related to broadcasting transactions, and enables APIs which can retrieve detailed information diff --git a/installer/config.json.example b/installer/config.json.example index 1bb94d2b03..3eefcf69ef 100644 --- a/installer/config.json.example +++ b/installer/config.json.example @@ -1,5 +1,5 @@ { - "Version": 28, + "Version": 27, "AccountUpdatesStatsInterval": 5000000000, "AccountsRebuildSynchronousMode": 1, "AgreementIncomingBundlesQueueLength": 15, diff --git a/ledger/acctonline.go b/ledger/acctonline.go index 28ced166ab..ebc6174187 100644 --- a/ledger/acctonline.go +++ b/ledger/acctonline.go @@ -191,7 +191,7 @@ func (ao *onlineAccounts) initializeFromDisk(l ledgerForTracker, lastBalancesRou if !ao.disableCache { ao.baseOnlineAccounts.init(ao.log, baseAccountsPendingAccountsBufferSize, baseAccountsPendingAccountsWarnThreshold) } else { - ao.baseOnlineAccounts.init(ao.log, 0, 1) + ao.baseOnlineAccounts.init(ao.log, 0, 0) } return } diff --git a/ledger/acctupdates.go b/ledger/acctupdates.go index 5abe05499c..d3caf1ff60 100644 --- a/ledger/acctupdates.go +++ b/ledger/acctupdates.go @@ -972,9 +972,9 @@ func (au *accountUpdates) initializeFromDisk(l ledgerForTracker, lastBalancesRou au.baseResources.init(au.log, baseResourcesPendingAccountsBufferSize, baseResourcesPendingAccountsWarnThreshold) au.baseKVs.init(au.log, baseKVPendingBufferSize, baseKVPendingWarnThreshold) } else { - au.baseAccounts.init(au.log, 0, 1) - au.baseResources.init(au.log, 0, 1) - au.baseKVs.init(au.log, 0, 1) + au.baseAccounts.init(au.log, 0, 0) + au.baseResources.init(au.log, 0, 0) + au.baseKVs.init(au.log, 0, 0) } return } diff --git a/test/testdata/configs/config-v27.json b/test/testdata/configs/config-v27.json index 137578e0fa..76d25158c4 100644 --- a/test/testdata/configs/config-v27.json +++ b/test/testdata/configs/config-v27.json @@ -28,6 +28,7 @@ "DNSSecurityFlags": 1, "DeadlockDetection": 0, "DeadlockDetectionThreshold": 30, + "DisableLedgerLRUCache": false, "DisableLocalhostConnectionRateLimit": true, "DisableNetworking": false, "DisableOutgoingConnectionThrottling": false, diff --git a/test/testdata/configs/config-v28.json b/test/testdata/configs/config-v28.json deleted file mode 100644 index b17a15149c..0000000000 --- a/test/testdata/configs/config-v28.json +++ /dev/null @@ -1,117 +0,0 @@ -{ - "Version": 28, - "AccountUpdatesStatsInterval": 5000000000, - "AccountsRebuildSynchronousMode": 1, - "AgreementIncomingBundlesQueueLength": 15, - "AgreementIncomingProposalsQueueLength": 50, - "AgreementIncomingVotesQueueLength": 20000, - "AnnounceParticipationKey": true, - "Archival": false, - "BaseLoggerDebugLevel": 4, - "BlockServiceCustomFallbackEndpoints": "", - "BroadcastConnectionsLimit": -1, - "CadaverDirectory": "", - "CadaverSizeTarget": 0, - "CatchpointFileHistoryLength": 365, - "CatchpointInterval": 10000, - "CatchpointTracking": 0, - "CatchupBlockDownloadRetryAttempts": 1000, - "CatchupBlockValidateMode": 0, - "CatchupFailurePeerRefreshRate": 10, - "CatchupGossipBlockFetchTimeoutSec": 4, - "CatchupHTTPBlockFetchTimeoutSec": 4, - "CatchupLedgerDownloadRetryAttempts": 50, - "CatchupParallelBlocks": 16, - "ConnectionsRateLimitingCount": 60, - "ConnectionsRateLimitingWindowSeconds": 1, - "DNSBootstrapID": ".algorand.network", - "DNSSecurityFlags": 1, - "DeadlockDetection": 0, - "DeadlockDetectionThreshold": 30, - "DisableLedgerLRUCache": false, - "DisableLocalhostConnectionRateLimit": true, - "DisableNetworking": false, - "DisableOutgoingConnectionThrottling": false, - "EnableAccountUpdatesStats": false, - "EnableAgreementReporting": false, - "EnableAgreementTimeMetrics": false, - "EnableAssembleStats": false, - "EnableBlockService": false, - "EnableBlockServiceFallbackToArchiver": true, - "EnableCatchupFromArchiveServers": false, - "EnableDeveloperAPI": false, - "EnableExperimentalAPI": false, - "EnableGossipBlockService": true, - "EnableIncomingMessageFilter": false, - "EnableLedgerService": false, - "EnableMetricReporting": false, - "EnableOutgoingNetworkMessageFiltering": true, - "EnablePingHandler": true, - "EnableProcessBlockStats": false, - "EnableProfiler": false, - "EnableRequestLogger": false, - "EnableRuntimeMetrics": false, - "EnableTopAccountsReporting": false, - "EnableTxBacklogRateLimiting": false, - "EnableUsageLog": false, - "EnableVerbosedTransactionSyncLogging": false, - "EndpointAddress": "127.0.0.1:0", - "FallbackDNSResolverAddress": "", - "ForceFetchTransactions": false, - "ForceRelayMessages": false, - "GossipFanout": 4, - "HeartbeatUpdateInterval": 600, - "IncomingConnectionsLimit": 2400, - "IncomingMessageFilterBucketCount": 5, - "IncomingMessageFilterBucketSize": 512, - "IsIndexerActive": false, - "LedgerSynchronousMode": 2, - "LogArchiveMaxAge": "", - "LogArchiveName": "node.archive.log", - "LogSizeLimit": 1073741824, - "MaxAPIBoxPerApplication": 100000, - "MaxAPIResourcesPerAccount": 100000, - "MaxAcctLookback": 4, - "MaxCatchpointDownloadDuration": 7200000000000, - "MaxConnectionsPerIP": 15, - "MinCatchpointFileDownloadBytesPerSecond": 20480, - "NetAddress": "", - "NetworkMessageTraceServer": "", - "NetworkProtocolVersion": "", - "NodeExporterListenAddress": ":9100", - "NodeExporterPath": "./node_exporter", - "OptimizeAccountsDatabaseOnStartup": false, - "OutgoingMessageFilterBucketCount": 3, - "OutgoingMessageFilterBucketSize": 128, - "ParticipationKeysRefreshInterval": 60000000000, - "PeerConnectionsUpdateInterval": 3600, - "PeerPingPeriodSeconds": 0, - "PriorityPeers": {}, - "ProposalAssemblyTime": 500000000, - "PublicAddress": "", - "ReconnectTime": 60000000000, - "ReservedFDs": 256, - "RestConnectionsHardLimit": 2048, - "RestConnectionsSoftLimit": 1024, - "RestReadTimeoutSeconds": 15, - "RestWriteTimeoutSeconds": 120, - "RunHosted": false, - "SuggestedFeeBlockHistory": 3, - "SuggestedFeeSlidingWindowSize": 50, - "TLSCertFile": "", - "TLSKeyFile": "", - "TelemetryToLog": true, - "TransactionSyncDataExchangeRate": 0, - "TransactionSyncSignificantMessageThreshold": 0, - "TxBacklogReservedCapacityPerPeer": 20, - "TxBacklogServiceRateWindowSeconds": 10, - "TxBacklogSize": 26000, - "TxIncomingFilteringFlags": 1, - "TxPoolExponentialIncreaseFactor": 2, - "TxPoolSize": 75000, - "TxSyncIntervalSeconds": 60, - "TxSyncServeResponseSize": 1000000, - "TxSyncTimeoutSeconds": 30, - "UseXForwardedForAddressField": "", - "VerifiedTranscationsCacheSize": 150000 -} From 6cf1485af0b2687e87155275b9445e68ee1a3ba0 Mon Sep 17 00:00:00 2001 From: Hang Su Date: Thu, 2 Feb 2023 17:01:35 -0500 Subject: [PATCH 19/31] per pr comment, t skip, ledger testing --- ledger/acctupdates_test.go | 2 +- ledger/catchpointtracker_test.go | 8 ++++++ ledger/ledger_test.go | 21 ++++------------ ledger/testing/withAndWithoutCache.go | 35 +++++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 17 deletions(-) create mode 100644 ledger/testing/withAndWithoutCache.go diff --git a/ledger/acctupdates_test.go b/ledger/acctupdates_test.go index 2d871799b4..fc8b2efff5 100644 --- a/ledger/acctupdates_test.go +++ b/ledger/acctupdates_test.go @@ -594,7 +594,7 @@ func TestAcctUpdates(t *testing.T) { partitiontest.PartitionTest(t) conf := config.GetDefaultLocal() - withAndWithoutLRUCache(t, conf, testAcctUpdates) + ledgertesting.WithAndWithoutLRUCache(t, conf, testAcctUpdates) } func BenchmarkBalancesChanges(b *testing.B) { diff --git a/ledger/catchpointtracker_test.go b/ledger/catchpointtracker_test.go index f134fcd418..e442c4030c 100644 --- a/ledger/catchpointtracker_test.go +++ b/ledger/catchpointtracker_test.go @@ -377,6 +377,10 @@ func BenchmarkLargeCatchpointDataWriting(b *testing.B) { func TestReproducibleCatchpointLabels(t *testing.T) { partitiontest.PartitionTest(t) + if runtime.GOARCH == "arm" || runtime.GOARCH == "arm64" { + t.Skip("This test is too slow on ARM and causes CI builds to time out") + } + // create new protocol version, which has lower lookback testProtocolVersion := protocol.ConsensusVersion("test-protocol-TestReproducibleCatchpointLabels") protoParams := config.Consensus[protocol.ConsensusCurrentVersion] @@ -1470,6 +1474,10 @@ func TestHashContract(t *testing.T) { func TestCatchpointFastUpdates(t *testing.T) { partitiontest.PartitionTest(t) + if runtime.GOARCH == "arm" || runtime.GOARCH == "arm64" { + t.Skip("This test is too slow on ARM and causes CI builds to time out") + } + proto := config.Consensus[protocol.ConsensusCurrentVersion] accts := []map[basics.Address]basics.AccountData{ledgertesting.RandomAccounts(20, true)} diff --git a/ledger/ledger_test.go b/ledger/ledger_test.go index b0189a8e62..9a001e7ecd 100644 --- a/ledger/ledger_test.go +++ b/ledger/ledger_test.go @@ -197,17 +197,6 @@ func (l *Ledger) addBlockTxns(t *testing.T, accounts map[basics.Address]basics.A return l.AddBlock(blk, agreement.Certificate{}) } -func withAndWithoutLRUCache(t *testing.T, cfg config.Local, test func(t *testing.T, cfg config.Local)) { - cfg.DisableLedgerLRUCache = false - t.Run(fmt.Sprintf("test with lru cache"), func(t *testing.T) { - test(t, cfg) - }) - cfg.DisableLedgerLRUCache = true - t.Run(fmt.Sprintf("test without lru cache"), func(t *testing.T) { - test(t, cfg) - }) -} - func testLedgerBasic(t *testing.T, cfg config.Local) { genesisInitState, _ := ledgertesting.GenerateInitState(t, protocol.ConsensusCurrentVersion, 100) const inMem = true @@ -222,7 +211,7 @@ func TestLedgerBasic(t *testing.T) { cfg := config.GetDefaultLocal() cfg.Archival = true - withAndWithoutLRUCache(t, cfg, testLedgerBasic) + ledgertesting.WithAndWithoutLRUCache(t, cfg, testLedgerBasic) } func TestLedgerBlockHeaders(t *testing.T) { @@ -1554,7 +1543,7 @@ func TestLedgerReload(t *testing.T) { partitiontest.PartitionTest(t) cfg := config.GetDefaultLocal() cfg.Archival = true - withAndWithoutLRUCache(t, cfg, testLedgerReload) + ledgertesting.WithAndWithoutLRUCache(t, cfg, testLedgerReload) } func TestWaitLedgerReload(t *testing.T) { @@ -2954,7 +2943,7 @@ func TestVotersReloadFromDisk(t *testing.T) { cfg.Archival = false cfg.MaxAcctLookback = proto.StateProofInterval - proto.StateProofVotersLookback - 10 - withAndWithoutLRUCache(t, cfg, testVotersReloadFromDisk) + ledgertesting.WithAndWithoutLRUCache(t, cfg, testVotersReloadFromDisk) } func testVotersReloadFromDiskAfterOneStateProofCommitted(t *testing.T, cfg config.Local) { @@ -3022,7 +3011,7 @@ func TestVotersReloadFromDiskAfterOneStateProofCommitted(t *testing.T) { cfg.Archival = false cfg.MaxAcctLookback = proto.StateProofInterval - proto.StateProofVotersLookback - 10 - withAndWithoutLRUCache(t, cfg, testVotersReloadFromDiskAfterOneStateProofCommitted) + ledgertesting.WithAndWithoutLRUCache(t, cfg, testVotersReloadFromDiskAfterOneStateProofCommitted) } func testVotersReloadFromDiskPassRecoveryPeriod(t *testing.T, cfg config.Local) { @@ -3093,5 +3082,5 @@ func TestVotersReloadFromDiskPassRecoveryPeriod(t *testing.T) { cfg.Archival = false cfg.MaxAcctLookback = proto.StateProofInterval - proto.StateProofVotersLookback - 10 - withAndWithoutLRUCache(t, cfg, testVotersReloadFromDiskPassRecoveryPeriod) + ledgertesting.WithAndWithoutLRUCache(t, cfg, testVotersReloadFromDiskPassRecoveryPeriod) } diff --git a/ledger/testing/withAndWithoutCache.go b/ledger/testing/withAndWithoutCache.go new file mode 100644 index 0000000000..3753ff6ef9 --- /dev/null +++ b/ledger/testing/withAndWithoutCache.go @@ -0,0 +1,35 @@ +// Copyright (C) 2019-2023 Algorand, Inc. +// This file is part of go-algorand +// +// go-algorand is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// go-algorand is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with go-algorand. If not, see . + +package testing + +import ( + "fmt" + "testing" + + "github.com/algorand/go-algorand/config" +) + +func WithAndWithoutLRUCache(t *testing.T, cfg config.Local, test func(t *testing.T, cfg config.Local)) { + cfg.DisableLedgerLRUCache = false + t.Run(fmt.Sprintf("test with lru cache"), func(t *testing.T) { + test(t, cfg) + }) + cfg.DisableLedgerLRUCache = true + t.Run(fmt.Sprintf("test without lru cache"), func(t *testing.T) { + test(t, cfg) + }) +} From e88397accaffb4e7887e31dc13e094da9ea8a3da Mon Sep 17 00:00:00 2001 From: Hang Su Date: Thu, 2 Feb 2023 17:05:58 -0500 Subject: [PATCH 20/31] barking dog --- ledger/testing/withAndWithoutCache.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ledger/testing/withAndWithoutCache.go b/ledger/testing/withAndWithoutCache.go index 3753ff6ef9..fe5b9f112e 100644 --- a/ledger/testing/withAndWithoutCache.go +++ b/ledger/testing/withAndWithoutCache.go @@ -17,7 +17,6 @@ package testing import ( - "fmt" "testing" "github.com/algorand/go-algorand/config" @@ -25,11 +24,11 @@ import ( func WithAndWithoutLRUCache(t *testing.T, cfg config.Local, test func(t *testing.T, cfg config.Local)) { cfg.DisableLedgerLRUCache = false - t.Run(fmt.Sprintf("test with lru cache"), func(t *testing.T) { + t.Run("test with lru cache", func(t *testing.T) { test(t, cfg) }) cfg.DisableLedgerLRUCache = true - t.Run(fmt.Sprintf("test without lru cache"), func(t *testing.T) { + t.Run("test without lru cache", func(t *testing.T) { test(t, cfg) }) } From aee23ab6282d91ab6d31b1b15c0e47ff8fd0f6e1 Mon Sep 17 00:00:00 2001 From: Hang Su Date: Thu, 2 Feb 2023 18:01:21 -0500 Subject: [PATCH 21/31] minor --- config/local_defaults.go | 2 +- ledger/testing/withAndWithoutCache.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/config/local_defaults.go b/config/local_defaults.go index 81dda311a5..48ddae4be9 100644 --- a/config/local_defaults.go +++ b/config/local_defaults.go @@ -20,7 +20,7 @@ package config var defaultLocal = Local{ - Version: 28, + Version: 27, AccountUpdatesStatsInterval: 5000000000, AccountsRebuildSynchronousMode: 1, AgreementIncomingBundlesQueueLength: 15, diff --git a/ledger/testing/withAndWithoutCache.go b/ledger/testing/withAndWithoutCache.go index fe5b9f112e..0bb1e75098 100644 --- a/ledger/testing/withAndWithoutCache.go +++ b/ledger/testing/withAndWithoutCache.go @@ -22,6 +22,7 @@ import ( "github.com/algorand/go-algorand/config" ) +// WithAndWithoutLRUCache allows for running a test with ledger LRU cache activated and deactivated. func WithAndWithoutLRUCache(t *testing.T, cfg config.Local, test func(t *testing.T, cfg config.Local)) { cfg.DisableLedgerLRUCache = false t.Run("test with lru cache", func(t *testing.T) { From f21eb0776182f7c34e695aa8ee2525eac326502a Mon Sep 17 00:00:00 2001 From: Hang Su Date: Sat, 4 Feb 2023 20:05:59 -0500 Subject: [PATCH 22/31] codec '' tag for DisableLRUCache --- config/config_test.go | 3 +++ config/localTemplate.go | 2 +- installer/config.json.example | 1 - test/testdata/configs/config-v27.json | 1 - 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/config/config_test.go b/config/config_test.go index 1e24fa4591..ba89e018a7 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -513,6 +513,9 @@ func TestLocal_StructTags(t *testing.T) { } require.True(t, foundTag) expectedTag = expectedTag[:len(expectedTag)-1] + if field.Name == "DisableLedgerLRUCache" { + continue + } require.Equal(t, expectedTag, string(field.Tag)) } } diff --git a/config/localTemplate.go b/config/localTemplate.go index 04b4fb6faa..1d9806c98d 100644 --- a/config/localTemplate.go +++ b/config/localTemplate.go @@ -495,7 +495,7 @@ type Local struct { // DisableLedgerLRUCache disables LRU caches in ledger for testing purpose. // Note that we turn it on for only testing purpose, not supposed to use it in real production environment. - DisableLedgerLRUCache bool `version[27]:"false"` + DisableLedgerLRUCache bool `version[27]:"false" codec:""` // EnableFollowMode launches the node in "follower" mode. This turns off the agreement service, // and APIs related to broadcasting transactions, and enables APIs which can retrieve detailed information diff --git a/installer/config.json.example b/installer/config.json.example index 3eefcf69ef..52b86764ed 100644 --- a/installer/config.json.example +++ b/installer/config.json.example @@ -28,7 +28,6 @@ "DNSSecurityFlags": 1, "DeadlockDetection": 0, "DeadlockDetectionThreshold": 30, - "DisableLedgerLRUCache": false, "DisableLocalhostConnectionRateLimit": true, "DisableNetworking": false, "DisableOutgoingConnectionThrottling": false, diff --git a/test/testdata/configs/config-v27.json b/test/testdata/configs/config-v27.json index 76d25158c4..137578e0fa 100644 --- a/test/testdata/configs/config-v27.json +++ b/test/testdata/configs/config-v27.json @@ -28,7 +28,6 @@ "DNSSecurityFlags": 1, "DeadlockDetection": 0, "DeadlockDetectionThreshold": 30, - "DisableLedgerLRUCache": false, "DisableLocalhostConnectionRateLimit": true, "DisableNetworking": false, "DisableOutgoingConnectionThrottling": false, From 138e3f44e113e2e95bf1b55391d0bf06fbc18f96 Mon Sep 17 00:00:00 2001 From: Hang Su Date: Mon, 6 Feb 2023 08:40:46 -0500 Subject: [PATCH 23/31] try to use codec:'-' --- config/localTemplate.go | 2 +- installer/config.json.example | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/config/localTemplate.go b/config/localTemplate.go index 1d9806c98d..645bb371af 100644 --- a/config/localTemplate.go +++ b/config/localTemplate.go @@ -495,7 +495,7 @@ type Local struct { // DisableLedgerLRUCache disables LRU caches in ledger for testing purpose. // Note that we turn it on for only testing purpose, not supposed to use it in real production environment. - DisableLedgerLRUCache bool `version[27]:"false" codec:""` + DisableLedgerLRUCache bool `version[27]:"false" codec:"-"` // EnableFollowMode launches the node in "follower" mode. This turns off the agreement service, // and APIs related to broadcasting transactions, and enables APIs which can retrieve detailed information diff --git a/installer/config.json.example b/installer/config.json.example index 52b86764ed..3eefcf69ef 100644 --- a/installer/config.json.example +++ b/installer/config.json.example @@ -28,6 +28,7 @@ "DNSSecurityFlags": 1, "DeadlockDetection": 0, "DeadlockDetectionThreshold": 30, + "DisableLedgerLRUCache": false, "DisableLocalhostConnectionRateLimit": true, "DisableNetworking": false, "DisableOutgoingConnectionThrottling": false, From 210bc1798f05ba6bf6156120d6db07194b5b0074 Mon Sep 17 00:00:00 2001 From: Hang Su Date: Mon, 6 Feb 2023 10:23:06 -0500 Subject: [PATCH 24/31] workaround fix in defaultGenerator logic to skip field codec:'-' --- config/defaultsGenerator/defaultsGenerator.go | 6 ++++++ installer/config.json.example | 1 - 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/config/defaultsGenerator/defaultsGenerator.go b/config/defaultsGenerator/defaultsGenerator.go index 9c3365f895..983fa95f62 100644 --- a/config/defaultsGenerator/defaultsGenerator.go +++ b/config/defaultsGenerator/defaultsGenerator.go @@ -112,6 +112,12 @@ func prettyPrint(c config.Local, format string) (out string) { } for fieldIdx, field := range fields { + // skip fields in Local with tag `codec:"-"` (for DisableLedgerLRUCache) + if format == "json" && field.Tag.Get("codec") == "-" { + continue + } + + // normal generator logic switch field.Type.Kind() { case reflect.Bool: v := reflect.ValueOf(&c).Elem().FieldByName(field.Name).Bool() diff --git a/installer/config.json.example b/installer/config.json.example index 3eefcf69ef..52b86764ed 100644 --- a/installer/config.json.example +++ b/installer/config.json.example @@ -28,7 +28,6 @@ "DNSSecurityFlags": 1, "DeadlockDetection": 0, "DeadlockDetectionThreshold": 30, - "DisableLedgerLRUCache": false, "DisableLocalhostConnectionRateLimit": true, "DisableNetworking": false, "DisableOutgoingConnectionThrottling": false, From 37177c7fcbad21048d260669326eb912bfeac5eb Mon Sep 17 00:00:00 2001 From: Hang Su Date: Thu, 9 Feb 2023 10:13:38 -0500 Subject: [PATCH 25/31] revert codec:'-' related commits --- config/config_test.go | 3 --- config/defaultsGenerator/defaultsGenerator.go | 6 ------ config/localTemplate.go | 7 ++++--- installer/config.json.example | 1 + test/testdata/configs/config-v27.json | 1 + 5 files changed, 6 insertions(+), 12 deletions(-) diff --git a/config/config_test.go b/config/config_test.go index ba89e018a7..1e24fa4591 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -513,9 +513,6 @@ func TestLocal_StructTags(t *testing.T) { } require.True(t, foundTag) expectedTag = expectedTag[:len(expectedTag)-1] - if field.Name == "DisableLedgerLRUCache" { - continue - } require.Equal(t, expectedTag, string(field.Tag)) } } diff --git a/config/defaultsGenerator/defaultsGenerator.go b/config/defaultsGenerator/defaultsGenerator.go index 983fa95f62..9c3365f895 100644 --- a/config/defaultsGenerator/defaultsGenerator.go +++ b/config/defaultsGenerator/defaultsGenerator.go @@ -112,12 +112,6 @@ func prettyPrint(c config.Local, format string) (out string) { } for fieldIdx, field := range fields { - // skip fields in Local with tag `codec:"-"` (for DisableLedgerLRUCache) - if format == "json" && field.Tag.Get("codec") == "-" { - continue - } - - // normal generator logic switch field.Type.Kind() { case reflect.Bool: v := reflect.ValueOf(&c).Elem().FieldByName(field.Name).Bool() diff --git a/config/localTemplate.go b/config/localTemplate.go index 645bb371af..8172545575 100644 --- a/config/localTemplate.go +++ b/config/localTemplate.go @@ -493,9 +493,10 @@ type Local struct { // guarantees in terms of functionality or future support. EnableExperimentalAPI bool `version[26]:"false"` - // DisableLedgerLRUCache disables LRU caches in ledger for testing purpose. - // Note that we turn it on for only testing purpose, not supposed to use it in real production environment. - DisableLedgerLRUCache bool `version[27]:"false" codec:"-"` + // DisableLedgerLRUCache disables LRU caches in ledger. + // Setting it to TRUE might result in significant performance degradation + // and SHOULD NOT be used for other reasons than testing. + DisableLedgerLRUCache bool `version[27]:"false"` // EnableFollowMode launches the node in "follower" mode. This turns off the agreement service, // and APIs related to broadcasting transactions, and enables APIs which can retrieve detailed information diff --git a/installer/config.json.example b/installer/config.json.example index 52b86764ed..3eefcf69ef 100644 --- a/installer/config.json.example +++ b/installer/config.json.example @@ -28,6 +28,7 @@ "DNSSecurityFlags": 1, "DeadlockDetection": 0, "DeadlockDetectionThreshold": 30, + "DisableLedgerLRUCache": false, "DisableLocalhostConnectionRateLimit": true, "DisableNetworking": false, "DisableOutgoingConnectionThrottling": false, diff --git a/test/testdata/configs/config-v27.json b/test/testdata/configs/config-v27.json index 137578e0fa..76d25158c4 100644 --- a/test/testdata/configs/config-v27.json +++ b/test/testdata/configs/config-v27.json @@ -28,6 +28,7 @@ "DNSSecurityFlags": 1, "DeadlockDetection": 0, "DeadlockDetectionThreshold": 30, + "DisableLedgerLRUCache": false, "DisableLocalhostConnectionRateLimit": true, "DisableNetworking": false, "DisableOutgoingConnectionThrottling": false, From 1caa8548181e860e659913172c894c169e881293 Mon Sep 17 00:00:00 2001 From: Hang Su Date: Thu, 9 Feb 2023 17:04:13 -0500 Subject: [PATCH 26/31] decrease test time by introducing randomness --- ledger/testing/consensusRange.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/ledger/testing/consensusRange.go b/ledger/testing/consensusRange.go index 2f6e4c6139..8b5f0dda57 100644 --- a/ledger/testing/consensusRange.go +++ b/ledger/testing/consensusRange.go @@ -17,6 +17,8 @@ package testing import ( + "crypto/rand" + "encoding/binary" "fmt" "testing" @@ -70,6 +72,15 @@ func versionStringFromIndex(index int) string { return version } +// rand16 samples randomness for TestConsensusRange, +// which tests with or without LRU Cache in ledger +func rand16(t *testing.T) uint16 { + var twobytes [2]byte + _, err := rand.Read(twobytes[:]) + require.NoError(t, err) + return binary.LittleEndian.Uint16(twobytes[:]) +} + // TestConsensusRange allows for running tests against a range of consensus // versions. Generally `start` will be the version that introduced the feature, // and `stop` will be 0 to indicate it should work right on up through vFuture. @@ -88,14 +99,12 @@ func TestConsensusRange(t *testing.T, start, stop int, test func(t *testing.T, v cfg := config.GetDefaultLocal() for i := start; i <= stop; i++ { version := versionStringFromIndex(i) + disable := rand16(t)%2 == 0 t.Run(fmt.Sprintf("cv=%s", version), func(t *testing.T) { + cfg.DisableLedgerLRUCache = disable test(t, i, consensusByNumber[i], cfg) }) } - cfg.DisableLedgerLRUCache = true - t.Run(fmt.Sprintf("cv=%s without LRU cache", versionStringFromIndex(stop)), func(t *testing.T) { - test(t, stop, consensusByNumber[stop], cfg) - }) } // BenchConsensusRange is for getting benchmarks across consensus versions. From 721a3361ac2f6830abd290c4968db1ba9779a70a Mon Sep 17 00:00:00 2001 From: Hang Su Date: Fri, 10 Feb 2023 11:23:39 -0500 Subject: [PATCH 27/31] log message on lru cache disabling --- ledger/testing/consensusRange.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ledger/testing/consensusRange.go b/ledger/testing/consensusRange.go index 8b5f0dda57..6b9dd0b9d4 100644 --- a/ledger/testing/consensusRange.go +++ b/ledger/testing/consensusRange.go @@ -100,7 +100,7 @@ func TestConsensusRange(t *testing.T, start, stop int, test func(t *testing.T, v for i := start; i <= stop; i++ { version := versionStringFromIndex(i) disable := rand16(t)%2 == 0 - t.Run(fmt.Sprintf("cv=%s", version), func(t *testing.T) { + t.Run(fmt.Sprintf("cv=%s,LRU-cache-disable=%t", version, disable), func(t *testing.T) { cfg.DisableLedgerLRUCache = disable test(t, i, consensusByNumber[i], cfg) }) From 922413a1ea829352d338daab5896eff92dfd2956 Mon Sep 17 00:00:00 2001 From: Hang Su Date: Fri, 10 Feb 2023 14:29:18 -0500 Subject: [PATCH 28/31] per chris comments on removing disable boolean field --- ledger/lruaccts.go | 22 ++++++++++++---------- ledger/lrukv.go | 18 +++++++++--------- ledger/lrukv_test.go | 1 - ledger/lruonlineaccts.go | 13 +++++++------ ledger/lruresources.go | 25 +++++++++++++------------ 5 files changed, 41 insertions(+), 38 deletions(-) diff --git a/ledger/lruaccts.go b/ledger/lruaccts.go index db37ffbe97..206282765f 100644 --- a/ledger/lruaccts.go +++ b/ledger/lruaccts.go @@ -23,24 +23,25 @@ import ( ) // lruAccounts provides a storage class for the most recently used accounts data. -// It doesn't have any synchronization primitive on it's own and require to be -// syncronized by the caller. +// It doesn't have any synchronization primitive on its own and require to be +// synchronized by the caller. type lruAccounts struct { // accountsList contain the list of persistedAccountData, where the front ones are the most "fresh" // and the ones on the back are the oldest. accountsList *persistedAccountDataList // accounts provides fast access to the various elements in the list by using the account address + // if lruAccounts is set with pendingWrites 0, then accounts is nil accounts map[basics.Address]*persistedAccountDataListNode // pendingAccounts are used as a way to avoid taking a write-lock. When the caller needs to "materialize" these, // it would call flushPendingWrites and these would be merged into the accounts/accountsList + // if lruAccounts is set with pendingWrites 0, then pendingAccounts is nil pendingAccounts chan store.PersistedAccountData // log interface; used for logging the threshold event. log logging.Logger // pendingWritesWarnThreshold is the threshold beyond we would write a warning for exceeding the number of pendingAccounts entries pendingWritesWarnThreshold int - // disableWriteAccounts is the boolean indicator that disables write into accounts - disableWriteAccounts bool + // if lruAccounts is set with pendingWrites 0, then pendingNotFound and notFound is nil pendingNotFound chan basics.Address notFound map[basics.Address]struct{} } @@ -49,13 +50,14 @@ type lruAccounts struct { // thread locking semantics : write lock func (m *lruAccounts) init(log logging.Logger, pendingWrites int, pendingWritesWarnThreshold int) { m.accountsList = newPersistedAccountList().allocateFreeNodes(pendingWrites) - m.accounts = make(map[basics.Address]*persistedAccountDataListNode, pendingWrites) - m.pendingAccounts = make(chan store.PersistedAccountData, pendingWrites) - m.notFound = make(map[basics.Address]struct{}, pendingWrites) - m.pendingNotFound = make(chan basics.Address, pendingWrites) + if pendingWrites > 0 { + m.accounts = make(map[basics.Address]*persistedAccountDataListNode, pendingWrites) + m.pendingAccounts = make(chan store.PersistedAccountData, pendingWrites) + m.notFound = make(map[basics.Address]struct{}, pendingWrites) + m.pendingNotFound = make(chan basics.Address, pendingWrites) + } m.log = log m.pendingWritesWarnThreshold = pendingWritesWarnThreshold - m.disableWriteAccounts = pendingWrites == 0 } // read the persistedAccountData object that the lruAccounts has for the given address. @@ -130,7 +132,7 @@ func (m *lruAccounts) writeNotFoundPending(addr basics.Address) { // to be promoted to the front of the list. // thread locking semantics : write lock func (m *lruAccounts) write(acctData store.PersistedAccountData) { - if m.disableWriteAccounts { + if m.accounts == nil { return } if el := m.accounts[acctData.Addr]; el != nil { diff --git a/ledger/lrukv.go b/ledger/lrukv.go index 703ca3dd2d..837a348d35 100644 --- a/ledger/lrukv.go +++ b/ledger/lrukv.go @@ -30,18 +30,20 @@ type cachedKVData struct { } // lruKV provides a storage class for the most recently used kv data. -// It doesn't have any synchronization primitive on it's own and require to be -// syncronized by the caller. +// It doesn't have any synchronization primitive on its own and require to be +// synchronized by the caller. type lruKV struct { // kvList contain the list of persistedKVData, where the front ones are the most "fresh" // and the ones on the back are the oldest. kvList *persistedKVDataList // kvs provides fast access to the various elements in the list by using the key + // if lruKV is set with pendingWrites 0, then kvs is nil kvs map[string]*persistedKVDataListNode // pendingKVs are used as a way to avoid taking a write-lock. When the caller needs to "materialize" these, // it would call flushPendingWrites and these would be merged into the kvs/kvList + // if lruKV is set with pendingWrites 0, then pendingKVs is nil pendingKVs chan cachedKVData // log interface; used for logging the threshold event. @@ -49,20 +51,18 @@ type lruKV struct { // pendingWritesWarnThreshold is the threshold beyond we would write a warning for exceeding the number of pendingKVs entries pendingWritesWarnThreshold int - - // disableWriteKV is the boolean indicator that disables write into kvs - disableWriteKV bool } // init initializes the lruKV for use. // thread locking semantics : write lock func (m *lruKV) init(log logging.Logger, pendingWrites int, pendingWritesWarnThreshold int) { m.kvList = newPersistedKVList().allocateFreeNodes(pendingWrites) - m.kvs = make(map[string]*persistedKVDataListNode, pendingWrites) - m.pendingKVs = make(chan cachedKVData, pendingWrites) + if pendingWrites > 0 { + m.kvs = make(map[string]*persistedKVDataListNode, pendingWrites) + m.pendingKVs = make(chan cachedKVData, pendingWrites) + } m.log = log m.pendingWritesWarnThreshold = pendingWritesWarnThreshold - m.disableWriteKV = pendingWrites == 0 } // read the persistedKVData object that the lruKV has for the given key. @@ -107,7 +107,7 @@ func (m *lruKV) writePending(kv store.PersistedKVData, key string) { // to be promoted to the front of the list. // thread locking semantics : write lock func (m *lruKV) write(kvData store.PersistedKVData, key string) { - if m.disableWriteKV { + if m.kvs == nil { return } if el := m.kvs[key]; el != nil { diff --git a/ledger/lrukv_test.go b/ledger/lrukv_test.go index e86703b4a2..ce0eb02c03 100644 --- a/ledger/lrukv_test.go +++ b/ledger/lrukv_test.go @@ -85,7 +85,6 @@ func TestLRUKVDisable(t *testing.T) { var baseKV lruKV baseKV.init(logging.TestingLog(t), 0, 1) - require.True(t, baseKV.disableWriteKV) kvNum := 5 diff --git a/ledger/lruonlineaccts.go b/ledger/lruonlineaccts.go index ddd0405157..e6825502e8 100644 --- a/ledger/lruonlineaccts.go +++ b/ledger/lruonlineaccts.go @@ -30,27 +30,28 @@ type lruOnlineAccounts struct { // and the ones on the back are the oldest. accountsList *persistedOnlineAccountDataList // accounts provides fast access to the various elements in the list by using the account address + // if lruOnlineAccounts is set with pendingWrites 0, then accounts is nil accounts map[basics.Address]*persistedOnlineAccountDataListNode // pendingAccounts are used as a way to avoid taking a write-lock. When the caller needs to "materialize" these, // it would call flushPendingWrites and these would be merged into the accounts/accountsList + // if lruOnlineAccounts is set with pendingWrites 0, then pendingAccounts is nil pendingAccounts chan store.PersistedOnlineAccountData // log interface; used for logging the threshold event. log logging.Logger // pendingWritesWarnThreshold is the threshold beyond we would write a warning for exceeding the number of pendingAccounts entries pendingWritesWarnThreshold int - // disableWriteAccounts is the boolean indicator that disables write into accounts - disableWriteAccounts bool } // init initializes the lruAccounts for use. // thread locking semantics : write lock func (m *lruOnlineAccounts) init(log logging.Logger, pendingWrites int, pendingWritesWarnThreshold int) { m.accountsList = newPersistedOnlineAccountList().allocateFreeNodes(pendingWrites) - m.accounts = make(map[basics.Address]*persistedOnlineAccountDataListNode, pendingWrites) - m.pendingAccounts = make(chan store.PersistedOnlineAccountData, pendingWrites) + if pendingWrites > 0 { + m.accounts = make(map[basics.Address]*persistedOnlineAccountDataListNode, pendingWrites) + m.pendingAccounts = make(chan store.PersistedOnlineAccountData, pendingWrites) + } m.log = log m.pendingWritesWarnThreshold = pendingWritesWarnThreshold - m.disableWriteAccounts = pendingWrites == 0 } // read the persistedAccountData object that the lruAccounts has for the given address. @@ -95,7 +96,7 @@ func (m *lruOnlineAccounts) writePending(acct store.PersistedOnlineAccountData) // to be promoted to the front of the list. // thread locking semantics : write lock func (m *lruOnlineAccounts) write(acctData store.PersistedOnlineAccountData) { - if m.disableWriteAccounts { + if m.accounts == nil { return } if el := m.accounts[acctData.Addr]; el != nil { diff --git a/ledger/lruresources.go b/ledger/lruresources.go index 4860ad5e34..e2c96aafcf 100644 --- a/ledger/lruresources.go +++ b/ledger/lruresources.go @@ -29,19 +29,21 @@ type cachedResourceData struct { address basics.Address } -// lruResources provides a storage class for the most recently used resources data. -// It doesn't have any synchronization primitive on it's own and require to be -// syncronized by the caller. +// lruResources provides a storage class for the most recently used resources' data. +// It doesn't have any synchronization primitive on its own and require to be +// synchronized by the caller. type lruResources struct { // resourcesList contain the list of persistedResourceData, where the front ones are the most "fresh" // and the ones on the back are the oldest. resourcesList *persistedResourcesDataList // resources provides fast access to the various elements in the list by using the account address + // if lruResources is set with pendingWrites 0, then resources is nil resources map[accountCreatable]*persistedResourcesDataListNode // pendingResources are used as a way to avoid taking a write-lock. When the caller needs to "materialize" these, // it would call flushPendingWrites and these would be merged into the resources/resourcesList + // if lruResources is set with pendingWrites 0, then pendingResources is nil pendingResources chan cachedResourceData // log interface; used for logging the threshold event. @@ -50,9 +52,7 @@ type lruResources struct { // pendingWritesWarnThreshold is the threshold beyond we would write a warning for exceeding the number of pendingResources entries pendingWritesWarnThreshold int - // disableWriteResources is the boolean indicator that disables write into resources - disableWriteResources bool - + // if lruResources is set with pendingWrites 0, then pendingNotFound and notFound is nil pendingNotFound chan accountCreatable notFound map[accountCreatable]struct{} } @@ -61,13 +61,14 @@ type lruResources struct { // thread locking semantics : write lock func (m *lruResources) init(log logging.Logger, pendingWrites int, pendingWritesWarnThreshold int) { m.resourcesList = newPersistedResourcesList().allocateFreeNodes(pendingWrites) - m.resources = make(map[accountCreatable]*persistedResourcesDataListNode, pendingWrites) - m.pendingResources = make(chan cachedResourceData, pendingWrites) - m.notFound = make(map[accountCreatable]struct{}, pendingWrites) - m.pendingNotFound = make(chan accountCreatable, pendingWrites) + if pendingWrites > 0 { + m.resources = make(map[accountCreatable]*persistedResourcesDataListNode, pendingWrites) + m.pendingResources = make(chan cachedResourceData, pendingWrites) + m.notFound = make(map[accountCreatable]struct{}, pendingWrites) + m.pendingNotFound = make(chan accountCreatable, pendingWrites) + } m.log = log m.pendingWritesWarnThreshold = pendingWritesWarnThreshold - m.disableWriteResources = pendingWrites == 0 } // read the persistedResourcesData object that the lruResources has for the given address and creatable index. @@ -153,7 +154,7 @@ func (m *lruResources) writeNotFoundPending(addr basics.Address, idx basics.Crea // to be promoted to the front of the list. // thread locking semantics : write lock func (m *lruResources) write(resData store.PersistedResourcesData, addr basics.Address) { - if m.disableWriteResources { + if m.resources == nil { return } if el := m.resources[accountCreatable{address: addr, index: resData.Aidx}]; el != nil { From 2b6e724505bfbdb742dda99857e3577fd2c45600 Mon Sep 17 00:00:00 2001 From: Hang Su Date: Wed, 15 Feb 2023 14:58:16 -0500 Subject: [PATCH 29/31] per pr comments --- ledger/lruaccts.go | 5 ++++- ledger/lrukv.go | 5 ++++- ledger/lruonlineaccts.go | 5 ++++- ledger/lruresources.go | 5 ++++- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/ledger/lruaccts.go b/ledger/lruaccts.go index 206282765f..a6962cab81 100644 --- a/ledger/lruaccts.go +++ b/ledger/lruaccts.go @@ -49,8 +49,8 @@ type lruAccounts struct { // init initializes the lruAccounts for use. // thread locking semantics : write lock func (m *lruAccounts) init(log logging.Logger, pendingWrites int, pendingWritesWarnThreshold int) { - m.accountsList = newPersistedAccountList().allocateFreeNodes(pendingWrites) if pendingWrites > 0 { + m.accountsList = newPersistedAccountList().allocateFreeNodes(pendingWrites) m.accounts = make(map[basics.Address]*persistedAccountDataListNode, pendingWrites) m.pendingAccounts = make(chan store.PersistedAccountData, pendingWrites) m.notFound = make(map[basics.Address]struct{}, pendingWrites) @@ -152,6 +152,9 @@ func (m *lruAccounts) write(acctData store.PersistedAccountData) { // recently used entries. // thread locking semantics : write lock func (m *lruAccounts) prune(newSize int) (removed int) { + if m.accounts == nil { + return + } for { if len(m.accounts) <= newSize { break diff --git a/ledger/lrukv.go b/ledger/lrukv.go index 837a348d35..420f87f5dc 100644 --- a/ledger/lrukv.go +++ b/ledger/lrukv.go @@ -56,8 +56,8 @@ type lruKV struct { // init initializes the lruKV for use. // thread locking semantics : write lock func (m *lruKV) init(log logging.Logger, pendingWrites int, pendingWritesWarnThreshold int) { - m.kvList = newPersistedKVList().allocateFreeNodes(pendingWrites) if pendingWrites > 0 { + m.kvList = newPersistedKVList().allocateFreeNodes(pendingWrites) m.kvs = make(map[string]*persistedKVDataListNode, pendingWrites) m.pendingKVs = make(chan cachedKVData, pendingWrites) } @@ -127,6 +127,9 @@ func (m *lruKV) write(kvData store.PersistedKVData, key string) { // recently used entries. // thread locking semantics : write lock func (m *lruKV) prune(newSize int) (removed int) { + if m.kvs == nil { + return + } for { if len(m.kvs) <= newSize { break diff --git a/ledger/lruonlineaccts.go b/ledger/lruonlineaccts.go index e6825502e8..cc8917bf57 100644 --- a/ledger/lruonlineaccts.go +++ b/ledger/lruonlineaccts.go @@ -45,8 +45,8 @@ type lruOnlineAccounts struct { // init initializes the lruAccounts for use. // thread locking semantics : write lock func (m *lruOnlineAccounts) init(log logging.Logger, pendingWrites int, pendingWritesWarnThreshold int) { - m.accountsList = newPersistedOnlineAccountList().allocateFreeNodes(pendingWrites) if pendingWrites > 0 { + m.accountsList = newPersistedOnlineAccountList().allocateFreeNodes(pendingWrites) m.accounts = make(map[basics.Address]*persistedOnlineAccountDataListNode, pendingWrites) m.pendingAccounts = make(chan store.PersistedOnlineAccountData, pendingWrites) } @@ -116,6 +116,9 @@ func (m *lruOnlineAccounts) write(acctData store.PersistedOnlineAccountData) { // recently used entries. // thread locking semantics : write lock func (m *lruOnlineAccounts) prune(newSize int) (removed int) { + if m.accounts == nil { + return + } for { if len(m.accounts) <= newSize { break diff --git a/ledger/lruresources.go b/ledger/lruresources.go index e2c96aafcf..779ca3cb95 100644 --- a/ledger/lruresources.go +++ b/ledger/lruresources.go @@ -60,8 +60,8 @@ type lruResources struct { // init initializes the lruResources for use. // thread locking semantics : write lock func (m *lruResources) init(log logging.Logger, pendingWrites int, pendingWritesWarnThreshold int) { - m.resourcesList = newPersistedResourcesList().allocateFreeNodes(pendingWrites) if pendingWrites > 0 { + m.resourcesList = newPersistedResourcesList().allocateFreeNodes(pendingWrites) m.resources = make(map[accountCreatable]*persistedResourcesDataListNode, pendingWrites) m.pendingResources = make(chan cachedResourceData, pendingWrites) m.notFound = make(map[accountCreatable]struct{}, pendingWrites) @@ -174,6 +174,9 @@ func (m *lruResources) write(resData store.PersistedResourcesData, addr basics.A // recently used entries. // thread locking semantics : write lock func (m *lruResources) prune(newSize int) (removed int) { + if m.resources == nil { + return + } for { if len(m.resources) <= newSize { break From f7283630277a3913399a5d69d64888c5140a3cb6 Mon Sep 17 00:00:00 2001 From: Hang Su Date: Wed, 15 Feb 2023 15:10:04 -0500 Subject: [PATCH 30/31] WithAndWithout test against TestAcctUpdatesUpdatesCorrectness --- ledger/acctupdates_test.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/ledger/acctupdates_test.go b/ledger/acctupdates_test.go index fc8b2efff5..66d14f5943 100644 --- a/ledger/acctupdates_test.go +++ b/ledger/acctupdates_test.go @@ -719,9 +719,14 @@ func BenchmarkCalibrateCacheNodeSize(b *testing.B) { func TestAcctUpdatesUpdatesCorrectness(t *testing.T) { partitiontest.PartitionTest(t) + cfgLocal := config.GetDefaultLocal() + ledgertesting.WithAndWithoutLRUCache(t, cfgLocal, testAcctUpdatesUpdatesCorrectness) +} + +func testAcctUpdatesUpdatesCorrectness(t *testing.T, cfg config.Local) { // create new protocol version, which has lower look back. testProtocolVersion := protocol.ConsensusCurrentVersion - maxAcctLookback := config.GetDefaultLocal().MaxAcctLookback + maxAcctLookback := cfg.MaxAcctLookback inMemory := true testFunction := func(t *testing.T) { @@ -746,8 +751,7 @@ func TestAcctUpdatesUpdatesCorrectness(t *testing.T) { accts[0][addr] = accountData } - conf := config.GetDefaultLocal() - au, _ := newAcctUpdates(t, ml, conf) + au, _ := newAcctUpdates(t, ml, cfg) defer au.close() // cover 10 genesis blocks From 5954351c1d37d56708629e2dd3d3d10f889fa162 Mon Sep 17 00:00:00 2001 From: Hang Su Date: Wed, 15 Feb 2023 17:52:09 -0500 Subject: [PATCH 31/31] per review comments --- ledger/testing/consensusRange.go | 18 ++++++++---------- ledger/txnbench_test.go | 4 ++-- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/ledger/testing/consensusRange.go b/ledger/testing/consensusRange.go index 6b9dd0b9d4..02ae83fce9 100644 --- a/ledger/testing/consensusRange.go +++ b/ledger/testing/consensusRange.go @@ -18,7 +18,6 @@ package testing import ( "crypto/rand" - "encoding/binary" "fmt" "testing" @@ -72,13 +71,13 @@ func versionStringFromIndex(index int) string { return version } -// rand16 samples randomness for TestConsensusRange, +// randBool samples randomness for TestConsensusRange, // which tests with or without LRU Cache in ledger -func rand16(t *testing.T) uint16 { - var twobytes [2]byte - _, err := rand.Read(twobytes[:]) +func randBool(t *testing.T) bool { + var byteBuffer [1]byte + _, err := rand.Read(byteBuffer[:]) require.NoError(t, err) - return binary.LittleEndian.Uint16(twobytes[:]) + return byteBuffer[0]%2 == 0 } // TestConsensusRange allows for running tests against a range of consensus @@ -99,7 +98,7 @@ func TestConsensusRange(t *testing.T, start, stop int, test func(t *testing.T, v cfg := config.GetDefaultLocal() for i := start; i <= stop; i++ { version := versionStringFromIndex(i) - disable := rand16(t)%2 == 0 + disable := randBool(t) t.Run(fmt.Sprintf("cv=%s,LRU-cache-disable=%t", version, disable), func(t *testing.T) { cfg.DisableLedgerLRUCache = disable test(t, i, consensusByNumber[i], cfg) @@ -108,15 +107,14 @@ func TestConsensusRange(t *testing.T, start, stop int, test func(t *testing.T, v } // BenchConsensusRange is for getting benchmarks across consensus versions. -func BenchConsensusRange(b *testing.B, start, stop int, bench func(t *testing.B, ver int, cv protocol.ConsensusVersion, cfg config.Local)) { +func BenchConsensusRange(b *testing.B, start, stop int, bench func(t *testing.B, ver int, cv protocol.ConsensusVersion)) { if stop == 0 { // Treat 0 as "future" stop = len(consensusByNumber) - 1 } - cfg := config.GetDefaultLocal() for i := start; i <= stop; i++ { version := versionStringFromIndex(i) b.Run(fmt.Sprintf("cv=%s", version), func(b *testing.B) { - bench(b, i, consensusByNumber[i], cfg) + bench(b, i, consensusByNumber[i]) }) } } diff --git a/ledger/txnbench_test.go b/ledger/txnbench_test.go index 5679af8df2..f2b4b8aa4a 100644 --- a/ledger/txnbench_test.go +++ b/ledger/txnbench_test.go @@ -35,8 +35,8 @@ import ( // BenchmarkTxnTypes compares the execution time of various txn types func BenchmarkTxnTypes(b *testing.B) { genBalances, addrs, _ := ledgertesting.NewTestGenesis() - ledgertesting.BenchConsensusRange(b, 30, 0, func(b *testing.B, ver int, cv protocol.ConsensusVersion, cfg config.Local) { - l := newSimpleLedgerWithConsensusVersion(b, genBalances, cv, cfg) + ledgertesting.BenchConsensusRange(b, 30, 0, func(b *testing.B, ver int, cv protocol.ConsensusVersion) { + l := newSimpleLedgerWithConsensusVersion(b, genBalances, cv, config.GetDefaultLocal()) defer l.Close() createasa := txntest.Txn{