From 75c2857761aa1cb2086578f386958f8c993b3470 Mon Sep 17 00:00:00 2001 From: Charlie Chen Date: Tue, 26 Nov 2024 18:27:50 -0600 Subject: [PATCH 1/4] use different database file names for btc signet and testnet4 --- zetaclient/orchestrator/bootstrap.go | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/zetaclient/orchestrator/bootstrap.go b/zetaclient/orchestrator/bootstrap.go index e1d89df0fd..ce9632383d 100644 --- a/zetaclient/orchestrator/bootstrap.go +++ b/zetaclient/orchestrator/bootstrap.go @@ -11,6 +11,7 @@ import ( "github.com/pkg/errors" "github.com/tonkeeper/tongo/ton" + "github.com/zeta-chain/node/pkg/chains" toncontracts "github.com/zeta-chain/node/pkg/contracts/ton" "github.com/zeta-chain/node/zetaclient/chains/base" btcobserver "github.com/zeta-chain/node/zetaclient/chains/bitcoin/observer" @@ -32,10 +33,6 @@ import ( "github.com/zeta-chain/node/zetaclient/metrics" ) -// btcDatabaseFilename is the Bitcoin database file name now used in mainnet, -// so we keep using it here for backward compatibility -const btcDatabaseFilename = "btc_chain_client" - // CreateSignerMap creates a map of interfaces.ChainSigner (by chainID) for all chains in the config. // Note that signer construction failure for a chain does not prevent the creation of signers for other chains. func CreateSignerMap( @@ -363,7 +360,7 @@ func syncObserverMap( continue } - database, err := db.NewFromSqlite(dbpath, btcDatabaseFilename, true) + database, err := db.NewFromSqlite(dbpath, btcDatabaseFileName(*rawChain), true) if err != nil { logger.Std.Error().Err(err).Msgf("unable to open database for BTC chain %d", chainID) continue @@ -481,6 +478,20 @@ func syncObserverMap( return added, removed, nil } +func btcDatabaseFileName(chain chains.Chain) string { + // btcDatabaseFilename is the Bitcoin database file name now used in mainnet and testnet3 + // so we keep using it here for backward compatibility + const btcDatabaseFilename = "btc_chain_client" + + // For additional bitcoin networks, we use the chain name as the database file name + switch chain.ChainId { + case chains.BitcoinMainnet.ChainId, chains.BitcoinTestnet.ChainId: + return btcDatabaseFilename + default: + return chain.Name + } +} + func makeTONClient( ctx context.Context, cfg config.TONConfig, From 92eb8ada9715299b5a4899708866c66e8503931d Mon Sep 17 00:00:00 2001 From: Charlie Chen Date: Tue, 26 Nov 2024 18:39:23 -0600 Subject: [PATCH 2/4] add changelog entry --- changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.md b/changelog.md index a3a78e0d82..571f6107f0 100644 --- a/changelog.md +++ b/changelog.md @@ -14,6 +14,7 @@ * [3206](https://github.com/zeta-chain/node/pull/3206) - skip Solana unsupported transaction version to not block inbound observation * [3184](https://github.com/zeta-chain/node/pull/3184) - zetaclient should not retry if inbound vote message validation fails +* [3225](https://github.com/zeta-chain/node/pull/3225) - use separate database file names for btc signet and testnet4 ## v23.0.0 From 54b452f77d31b8079aa32dc3d64793c970104329 Mon Sep 17 00:00:00 2001 From: Charlie Chen Date: Wed, 27 Nov 2024 12:41:05 -0600 Subject: [PATCH 3/4] update signet,testnet4 database file name pattern; add unit test --- zetaclient/orchestrator/bootstap_test.go | 40 ++++++++++++++++++++++++ zetaclient/orchestrator/bootstrap.go | 9 +++--- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/zetaclient/orchestrator/bootstap_test.go b/zetaclient/orchestrator/bootstap_test.go index d5f64c8500..95c52beeee 100644 --- a/zetaclient/orchestrator/bootstap_test.go +++ b/zetaclient/orchestrator/bootstap_test.go @@ -395,6 +395,46 @@ func TestCreateChainObserverMap(t *testing.T) { }) } +func TestBtcDatabaseFileName(t *testing.T) { + tests := []struct { + name string + chain chains.Chain + expected string + }{ + { + name: "should use legacy file name for bitcoin mainnet", + chain: chains.BitcoinMainnet, + expected: "btc_chain_client", + }, + { + name: "should use legacy file name for bitcoin testnet3", + chain: chains.BitcoinTestnet, + expected: "btc_chain_client", + }, + { + name: "should use new file name for bitcoin regtest", + chain: chains.BitcoinRegtest, + expected: "btc_chain_client_18444", + }, + { + name: "should use new file name for bitcoin signet", + chain: chains.BitcoinSignetTestnet, + expected: "btc_chain_client_18333", + }, + { + name: "should use new file name for bitcoin testnet4", + chain: chains.BitcoinTestnet4, + expected: "btc_chain_client_18334", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + assert.Equal(t, tt.expected, btcDatabaseFileName(tt.chain)) + }) + } +} + func chainParams(supportedChains []chains.Chain) ([]chains.Chain, map[int64]*observertypes.ChainParams) { params := make(map[int64]*observertypes.ChainParams) diff --git a/zetaclient/orchestrator/bootstrap.go b/zetaclient/orchestrator/bootstrap.go index ce9632383d..86d6325ed5 100644 --- a/zetaclient/orchestrator/bootstrap.go +++ b/zetaclient/orchestrator/bootstrap.go @@ -2,6 +2,7 @@ package orchestrator import ( "context" + "fmt" ethcommon "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/ethclient" @@ -479,16 +480,16 @@ func syncObserverMap( } func btcDatabaseFileName(chain chains.Chain) string { - // btcDatabaseFilename is the Bitcoin database file name now used in mainnet and testnet3 + // legacyBTCDatabaseFilename is the Bitcoin database file name now used in mainnet and testnet3 // so we keep using it here for backward compatibility - const btcDatabaseFilename = "btc_chain_client" + const legacyBTCDatabaseFilename = "btc_chain_client" // For additional bitcoin networks, we use the chain name as the database file name switch chain.ChainId { case chains.BitcoinMainnet.ChainId, chains.BitcoinTestnet.ChainId: - return btcDatabaseFilename + return legacyBTCDatabaseFilename default: - return chain.Name + return fmt.Sprintf("%s_%d", legacyBTCDatabaseFilename, chain.ChainId) } } From 7b113bd20aa6699e80946d92c82f6cdaa4c3b15b Mon Sep 17 00:00:00 2001 From: Charlie Chen Date: Fri, 29 Nov 2024 12:48:02 -0600 Subject: [PATCH 4/4] use chain name as bitcoin database suffix for regnet, signet and testnet4 --- zetaclient/orchestrator/bootstap_test.go | 6 +++--- zetaclient/orchestrator/bootstrap.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/zetaclient/orchestrator/bootstap_test.go b/zetaclient/orchestrator/bootstap_test.go index 95c52beeee..99f58b9e5b 100644 --- a/zetaclient/orchestrator/bootstap_test.go +++ b/zetaclient/orchestrator/bootstap_test.go @@ -414,17 +414,17 @@ func TestBtcDatabaseFileName(t *testing.T) { { name: "should use new file name for bitcoin regtest", chain: chains.BitcoinRegtest, - expected: "btc_chain_client_18444", + expected: "btc_chain_client_btc_regtest", }, { name: "should use new file name for bitcoin signet", chain: chains.BitcoinSignetTestnet, - expected: "btc_chain_client_18333", + expected: "btc_chain_client_btc_signet_testnet", }, { name: "should use new file name for bitcoin testnet4", chain: chains.BitcoinTestnet4, - expected: "btc_chain_client_18334", + expected: "btc_chain_client_btc_testnet4", }, } diff --git a/zetaclient/orchestrator/bootstrap.go b/zetaclient/orchestrator/bootstrap.go index 86d6325ed5..77793d341b 100644 --- a/zetaclient/orchestrator/bootstrap.go +++ b/zetaclient/orchestrator/bootstrap.go @@ -489,7 +489,7 @@ func btcDatabaseFileName(chain chains.Chain) string { case chains.BitcoinMainnet.ChainId, chains.BitcoinTestnet.ChainId: return legacyBTCDatabaseFilename default: - return fmt.Sprintf("%s_%d", legacyBTCDatabaseFilename, chain.ChainId) + return fmt.Sprintf("%s_%s", legacyBTCDatabaseFilename, chain.Name) } }