From ea7f2afe1063087a880519c0044890b290dccb84 Mon Sep 17 00:00:00 2001 From: ClaytonNorthey92 Date: Mon, 24 Jun 2024 11:46:10 -0400 Subject: [PATCH 01/14] allow TBC seeds to be overwritten if cfg seeds are set, use those, otherwise use the defaults for the network chosen --- service/tbc/tbc.go | 15 ++++++++++++++- service/tbc/tbcfork_test.go | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/service/tbc/tbc.go b/service/tbc/tbc.go index 131cc936..c52a5461 100644 --- a/service/tbc/tbc.go +++ b/service/tbc/tbc.go @@ -67,6 +67,9 @@ const ( var ( zeroHash = new(chainhash.Hash) // used to check if a hash is invalid + localnetSeeds = []string{ + "bitcoind", + } testnetSeeds = []string{ "testnet-seed.bitcoin.jonasschnelli.ch", "seed.tbtc.petertodd.org", @@ -157,6 +160,7 @@ type Config struct { PeersWanted int PrometheusListenAddress string PprofListenAddress string + Seeds []string } func NewDefaultConfig() *Config { @@ -260,10 +264,15 @@ func NewServer(cfg *Config) (*Server, error) { s.port = localnetPort s.wireNet = wire.TestNet s.chainParams = &chaincfg.RegressionNetParams + s.seeds = localnetSeeds default: return nil, fmt.Errorf("invalid network: %v", cfg.Network) } + if len(cfg.Seeds) > 0 { + s.seeds = cfg.Seeds + } + return s, nil } @@ -471,9 +480,13 @@ func (s *Server) localPeerManager(ctx context.Context) error { log.Tracef("localPeerManager") defer log.Tracef("localPeerManager exit") + if len(s.seeds) != 1 { + return fmt.Errorf("expecting 1 seed, received %d", len(s.seeds)) + } + peersWanted := 1 peerC := make(chan string, peersWanted) - address := net.JoinHostPort("127.0.0.1", s.port) + address := net.JoinHostPort(s.seeds[0], s.port) peer, err := NewPeer(s.wireNet, address) if err != nil { return fmt.Errorf("new peer: %w", err) diff --git a/service/tbc/tbcfork_test.go b/service/tbc/tbcfork_test.go index 9b3c5da5..1acd34e1 100644 --- a/service/tbc/tbcfork_test.go +++ b/service/tbc/tbcfork_test.go @@ -534,6 +534,7 @@ func TestFork(t *testing.T) { Network: networkLocalnet, PeersWanted: 1, PrometheusListenAddress: "", + Seeds: []string{"127.0.0.1"}, } _ = loggo.ConfigureLoggers(cfg.LogLevel) s, err := NewServer(cfg) From 430dc3041018fa449262e32496ddae7330a6df41 Mon Sep 17 00:00:00 2001 From: ClaytonNorthey92 Date: Mon, 24 Jun 2024 12:26:58 -0400 Subject: [PATCH 02/14] fixed missing seeding --- service/tbc/tbc_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/service/tbc/tbc_test.go b/service/tbc/tbc_test.go index c814d487..b487b9f7 100644 --- a/service/tbc/tbc_test.go +++ b/service/tbc/tbc_test.go @@ -821,6 +821,7 @@ func createTbcServer(ctx context.Context, t *testing.T, mappedPeerPort nat.Port) cfg.LevelDBHome = home cfg.Network = networkLocalnet cfg.ListenAddress = tcbListenAddress + cfg.Seeds = []string{"127.0.0.1"} tbcServer, err := NewServer(cfg) if err != nil { t.Fatal(err) From 02e80fa3193a3c13c6919a8aa0442b64b8c17b11 Mon Sep 17 00:00:00 2001 From: ClaytonNorthey92 Date: Mon, 24 Jun 2024 16:11:13 -0400 Subject: [PATCH 03/14] remove tbc Server.port --- service/tbc/tbc.go | 101 +++++++++++++++++++++++++----------- service/tbc/tbc_test.go | 2 +- service/tbc/tbcfork_test.go | 2 +- 3 files changed, 73 insertions(+), 32 deletions(-) diff --git a/service/tbc/tbc.go b/service/tbc/tbc.go index c52a5461..357ff334 100644 --- a/service/tbc/tbc.go +++ b/service/tbc/tbc.go @@ -67,22 +67,55 @@ const ( var ( zeroHash = new(chainhash.Hash) // used to check if a hash is invalid - localnetSeeds = []string{ - "bitcoind", - } - testnetSeeds = []string{ - "testnet-seed.bitcoin.jonasschnelli.ch", - "seed.tbtc.petertodd.org", - "seed.testnet.bitcoin.sprovoost.nl", - "testnet-seed.bluematt.me", - } - mainnetSeeds = []string{ - "seed.bitcoin.sipa.be", - "dnsseed.bluematt.me", - "dnsseed.bitcoin.dashjr.org", - "seed.bitcoinstats.com", - "seed.bitnodes.io", - "seed.bitcoin.jonasschnelli.ch", + localnetSeeds = []Seed{ + { + Host: "bitcoind", + Port: localnetPort, + }, + } + testnetSeeds = []Seed{ + { + Host: "testnet-seed.bitcoin.jonasschnelli.ch", + Port: testnetPort, + }, + { + Host: "seed.tbtc.petertodd.org", + Port: testnetPort, + }, + { + Host: "seed.testnet.bitcoin.sprovoost.nl", + Port: testnetPort, + }, + { + Host: "testnet-seed.bluematt.me", + Port: testnetPort, + }, + } + mainnetSeeds = []Seed{ + { + Host: "seed.bitcoin.sipa.be", + Port: mainnetPort, + }, + { + Host: "dnsseed.bluematt.me", + Port: mainnetPort, + }, + { + Host: "dnsseed.bitcoin.dashjr.org", + Port: mainnetPort, + }, + { + Host: "seed.bitcoinstats.com", + Port: mainnetPort, + }, + { + Host: "seed.bitnodes.io", + Port: mainnetPort, + }, + { + Host: "seed.bitcoin.jonasschnelli.ch", + Port: mainnetPort, + }, } ) @@ -149,6 +182,11 @@ func sliceChainHash(ch chainhash.Hash) []byte { return ch[:] } +type Seed struct { + Host string + Port string +} + type Config struct { AutoIndex bool BlockSanity bool @@ -160,7 +198,7 @@ type Config struct { PeersWanted int PrometheusListenAddress string PprofListenAddress string - Seeds []string + Seeds []Seed } func NewDefaultConfig() *Config { @@ -188,8 +226,7 @@ type Server struct { wireNet wire.BitcoinNet chainParams *chaincfg.Params timeSource blockchain.MedianTimeSource - port string - seeds []string + seeds []Seed peers map[string]*peer // active but not necessarily connected blocks *ttl.TTL // outstanding block downloads [hash]when/where @@ -251,17 +288,14 @@ func NewServer(cfg *Config) (*Server, error) { switch cfg.Network { case "mainnet": - s.port = mainnetPort s.wireNet = wire.MainNet s.chainParams = &chaincfg.MainNetParams s.seeds = mainnetSeeds case "testnet3": - s.port = testnetPort s.wireNet = wire.TestNet3 s.chainParams = &chaincfg.TestNet3Params s.seeds = testnetSeeds case networkLocalnet: - s.port = localnetPort s.wireNet = wire.TestNet s.chainParams = &chaincfg.RegressionNetParams s.seeds = localnetSeeds @@ -315,25 +349,32 @@ func (s *Server) seed(pctx context.Context, peersWanted int) ([]tbcd.Peer, error defer cancel() errorsSeen := 0 - var addrs []net.IP - for k := range s.seeds { - ips, err := resolver.LookupIP(ctx, "ip", s.seeds[k]) + var moreSeeds []Seed + for _, v := range s.seeds { + ips, err := resolver.LookupIP(ctx, "ip", net.JoinHostPort(v.Host, v.Port)) if err != nil { log.Errorf("lookup: %v", err) errorsSeen++ continue } - addrs = append(addrs, ips...) + + for _, ip := range ips { + moreSeeds = append(moreSeeds, Seed{ + Host: ip.String(), + Port: v.Port, + }) + } } + if errorsSeen == len(s.seeds) { return nil, errors.New("could not seed") } // insert into peers table - for k := range addrs { + for _, ms := range moreSeeds { peers = append(peers, tbcd.Peer{ - Host: addrs[k].String(), - Port: s.port, + Host: ms.Host, + Port: ms.Port, }) } @@ -486,7 +527,7 @@ func (s *Server) localPeerManager(ctx context.Context) error { peersWanted := 1 peerC := make(chan string, peersWanted) - address := net.JoinHostPort(s.seeds[0], s.port) + address := net.JoinHostPort(s.seeds[0].Host, s.seeds[0].Port) peer, err := NewPeer(s.wireNet, address) if err != nil { return fmt.Errorf("new peer: %w", err) diff --git a/service/tbc/tbc_test.go b/service/tbc/tbc_test.go index b487b9f7..54b0128c 100644 --- a/service/tbc/tbc_test.go +++ b/service/tbc/tbc_test.go @@ -821,7 +821,7 @@ func createTbcServer(ctx context.Context, t *testing.T, mappedPeerPort nat.Port) cfg.LevelDBHome = home cfg.Network = networkLocalnet cfg.ListenAddress = tcbListenAddress - cfg.Seeds = []string{"127.0.0.1"} + cfg.Seeds = []Seed{{Host: "127.0.0.1", Port: localnetPort}} tbcServer, err := NewServer(cfg) if err != nil { t.Fatal(err) diff --git a/service/tbc/tbcfork_test.go b/service/tbc/tbcfork_test.go index 1acd34e1..a959106b 100644 --- a/service/tbc/tbcfork_test.go +++ b/service/tbc/tbcfork_test.go @@ -534,7 +534,7 @@ func TestFork(t *testing.T) { Network: networkLocalnet, PeersWanted: 1, PrometheusListenAddress: "", - Seeds: []string{"127.0.0.1"}, + Seeds: []Seed{{Host: "127.0.0.1", Port: localnetPort}}, } _ = loggo.ConfigureLoggers(cfg.LogLevel) s, err := NewServer(cfg) From 229feefd2b54cb69934da6ff0e4a781f19c433f1 Mon Sep 17 00:00:00 2001 From: ClaytonNorthey92 Date: Tue, 25 Jun 2024 08:45:21 -0400 Subject: [PATCH 04/14] using string for seeds --- service/tbc/tbc.go | 101 +++++++++++++----------------------- service/tbc/tbc_test.go | 2 +- service/tbc/tbcfork_test.go | 2 +- 3 files changed, 38 insertions(+), 67 deletions(-) diff --git a/service/tbc/tbc.go b/service/tbc/tbc.go index 357ff334..727b3d9c 100644 --- a/service/tbc/tbc.go +++ b/service/tbc/tbc.go @@ -67,55 +67,22 @@ const ( var ( zeroHash = new(chainhash.Hash) // used to check if a hash is invalid - localnetSeeds = []Seed{ - { - Host: "bitcoind", - Port: localnetPort, - }, - } - testnetSeeds = []Seed{ - { - Host: "testnet-seed.bitcoin.jonasschnelli.ch", - Port: testnetPort, - }, - { - Host: "seed.tbtc.petertodd.org", - Port: testnetPort, - }, - { - Host: "seed.testnet.bitcoin.sprovoost.nl", - Port: testnetPort, - }, - { - Host: "testnet-seed.bluematt.me", - Port: testnetPort, - }, - } - mainnetSeeds = []Seed{ - { - Host: "seed.bitcoin.sipa.be", - Port: mainnetPort, - }, - { - Host: "dnsseed.bluematt.me", - Port: mainnetPort, - }, - { - Host: "dnsseed.bitcoin.dashjr.org", - Port: mainnetPort, - }, - { - Host: "seed.bitcoinstats.com", - Port: mainnetPort, - }, - { - Host: "seed.bitnodes.io", - Port: mainnetPort, - }, - { - Host: "seed.bitcoin.jonasschnelli.ch", - Port: mainnetPort, - }, + localnetSeeds = []string{ + fmt.Sprintf("bitcoind:%s", localnetPort), + } + testnetSeeds = []string{ + fmt.Sprintf("testnet-seed.bitcoin.jonasschnelli.ch:%s", testnetPort), + fmt.Sprintf("seed.tbtc.petertodd.org:%s", testnetPort), + fmt.Sprintf("seed.testnet.bitcoin.sprovoost.nl:%s", testnetPort), + fmt.Sprintf("testnet-seed.bluematt.me:%s", testnetPort), + } + mainnetSeeds = []string{ + fmt.Sprintf("seed.bitcoin.sipa.be:%s", mainnetPort), + fmt.Sprintf("dnsseed.bluematt.me:%s", mainnetPort), + fmt.Sprintf("dnsseed.bitcoin.dashjr.org:%s", mainnetPort), + fmt.Sprintf("seed.bitcoinstats.com:%s", mainnetPort), + fmt.Sprintf("seed.bitnodes.io:%s", mainnetPort), + fmt.Sprintf("seed.bitcoin.jonasschnelli.ch:%s", mainnetPort), } ) @@ -182,11 +149,6 @@ func sliceChainHash(ch chainhash.Hash) []byte { return ch[:] } -type Seed struct { - Host string - Port string -} - type Config struct { AutoIndex bool BlockSanity bool @@ -198,7 +160,7 @@ type Config struct { PeersWanted int PrometheusListenAddress string PprofListenAddress string - Seeds []Seed + Seeds []string } func NewDefaultConfig() *Config { @@ -226,7 +188,7 @@ type Server struct { wireNet wire.BitcoinNet chainParams *chaincfg.Params timeSource blockchain.MedianTimeSource - seeds []Seed + seeds []string peers map[string]*peer // active but not necessarily connected blocks *ttl.TTL // outstanding block downloads [hash]when/where @@ -349,9 +311,15 @@ func (s *Server) seed(pctx context.Context, peersWanted int) ([]tbcd.Peer, error defer cancel() errorsSeen := 0 - var moreSeeds []Seed + var moreSeeds []tbcd.Peer for _, v := range s.seeds { - ips, err := resolver.LookupIP(ctx, "ip", net.JoinHostPort(v.Host, v.Port)) + _, port, err := net.SplitHostPort(v) + if err != nil { + log.Errorf("SplitHostPort: %v", err) + errorsSeen++ + continue + } + ips, err := resolver.LookupIP(ctx, "ip", v) if err != nil { log.Errorf("lookup: %v", err) errorsSeen++ @@ -359,9 +327,9 @@ func (s *Server) seed(pctx context.Context, peersWanted int) ([]tbcd.Peer, error } for _, ip := range ips { - moreSeeds = append(moreSeeds, Seed{ + moreSeeds = append(moreSeeds, tbcd.Peer{ Host: ip.String(), - Port: v.Port, + Port: port, }) } } @@ -372,10 +340,7 @@ func (s *Server) seed(pctx context.Context, peersWanted int) ([]tbcd.Peer, error // insert into peers table for _, ms := range moreSeeds { - peers = append(peers, tbcd.Peer{ - Host: ms.Host, - Port: ms.Port, - }) + peers = append(peers, ms) } // return fake peers but don't save them to the database @@ -527,7 +492,13 @@ func (s *Server) localPeerManager(ctx context.Context) error { peersWanted := 1 peerC := make(chan string, peersWanted) - address := net.JoinHostPort(s.seeds[0].Host, s.seeds[0].Port) + + host, port, err := net.SplitHostPort(s.seeds[0]) + if err != nil { + return err + } + + address := net.JoinHostPort(host, port) peer, err := NewPeer(s.wireNet, address) if err != nil { return fmt.Errorf("new peer: %w", err) diff --git a/service/tbc/tbc_test.go b/service/tbc/tbc_test.go index 54b0128c..85e473cf 100644 --- a/service/tbc/tbc_test.go +++ b/service/tbc/tbc_test.go @@ -821,7 +821,7 @@ func createTbcServer(ctx context.Context, t *testing.T, mappedPeerPort nat.Port) cfg.LevelDBHome = home cfg.Network = networkLocalnet cfg.ListenAddress = tcbListenAddress - cfg.Seeds = []Seed{{Host: "127.0.0.1", Port: localnetPort}} + cfg.Seeds = []string{fmt.Sprintf("127.0.0.1:%s", localnetPort)} tbcServer, err := NewServer(cfg) if err != nil { t.Fatal(err) diff --git a/service/tbc/tbcfork_test.go b/service/tbc/tbcfork_test.go index a959106b..4fdbfea3 100644 --- a/service/tbc/tbcfork_test.go +++ b/service/tbc/tbcfork_test.go @@ -534,7 +534,7 @@ func TestFork(t *testing.T) { Network: networkLocalnet, PeersWanted: 1, PrometheusListenAddress: "", - Seeds: []Seed{{Host: "127.0.0.1", Port: localnetPort}}, + Seeds: []string{fmt.Sprintf("127.0.0.1:%s", localnetPort)}, } _ = loggo.ConfigureLoggers(cfg.LogLevel) s, err := NewServer(cfg) From 067c403954995b7fa8bf61e7f698b3dd0975a917 Mon Sep 17 00:00:00 2001 From: ClaytonNorthey92 Date: Tue, 25 Jun 2024 09:30:03 -0400 Subject: [PATCH 05/14] use host for lookupip --- service/tbc/tbc.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/service/tbc/tbc.go b/service/tbc/tbc.go index 727b3d9c..c3cd0e38 100644 --- a/service/tbc/tbc.go +++ b/service/tbc/tbc.go @@ -313,13 +313,13 @@ func (s *Server) seed(pctx context.Context, peersWanted int) ([]tbcd.Peer, error errorsSeen := 0 var moreSeeds []tbcd.Peer for _, v := range s.seeds { - _, port, err := net.SplitHostPort(v) + host, port, err := net.SplitHostPort(v) if err != nil { log.Errorf("SplitHostPort: %v", err) errorsSeen++ continue } - ips, err := resolver.LookupIP(ctx, "ip", v) + ips, err := resolver.LookupIP(ctx, "ip", host) if err != nil { log.Errorf("lookup: %v", err) errorsSeen++ From 1a05173943add3d0519edaa348b967145e346bb9 Mon Sep 17 00:00:00 2001 From: ClaytonNorthey92 Date: Tue, 25 Jun 2024 10:32:37 -0400 Subject: [PATCH 06/14] added TBC_SEEDS env config --- cmd/tbcd/tbcd.go | 7 +++++++ config/config.go | 3 +++ 2 files changed, 10 insertions(+) diff --git a/cmd/tbcd/tbcd.go b/cmd/tbcd/tbcd.go index 033023e8..ff917526 100644 --- a/cmd/tbcd/tbcd.go +++ b/cmd/tbcd/tbcd.go @@ -93,6 +93,12 @@ var ( Help: "address and port tbcd pprof listens on (open
/debug/pprof to see available profiles)", Print: config.PrintAll, }, + "TBC_SEEDS": config.Config{ + Value: &cfg.Seeds, + DefaultValue: []string{}, + Help: "list of tbc seeds, format of :", + Print: config.PrintAll, + }, } ) @@ -139,6 +145,7 @@ func _main() error { if err != nil { return fmt.Errorf("create tbc server: %w", err) } + // XXX remove, this is an illustration of calling the direct API of server // go func() { // for { diff --git a/config/config.go b/config/config.go index 04c2dcdd..9a2d05b7 100644 --- a/config/config.go +++ b/config/config.go @@ -12,6 +12,7 @@ import ( "reflect" "sort" "strconv" + "strings" ) type PrintMode int @@ -88,6 +89,8 @@ func Parse(c CfgMap) error { } reflect.ValueOf(v.Value).Elem().SetBool(val) + case reflect.Slice: + *(v.Value.(*[]string)) = strings.Split(envValue, ",") default: return fmt.Errorf("unsuported type for %v: %v", From 78af6febed399104260584460902edec975db1e5 Mon Sep 17 00:00:00 2001 From: ClaytonNorthey92 Date: Tue, 25 Jun 2024 10:36:56 -0400 Subject: [PATCH 07/14] Update service/tbc/tbc.go Co-authored-by: Joshua Sing --- service/tbc/tbc.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/tbc/tbc.go b/service/tbc/tbc.go index c3cd0e38..5c242455 100644 --- a/service/tbc/tbc.go +++ b/service/tbc/tbc.go @@ -315,7 +315,7 @@ func (s *Server) seed(pctx context.Context, peersWanted int) ([]tbcd.Peer, error for _, v := range s.seeds { host, port, err := net.SplitHostPort(v) if err != nil { - log.Errorf("SplitHostPort: %v", err) + log.Errorf("Failed to parse host/port: %v", err) errorsSeen++ continue } From 28ca4fa75499f23e738e1560bb54b703b4aeeb2c Mon Sep 17 00:00:00 2001 From: ClaytonNorthey92 Date: Tue, 25 Jun 2024 10:38:21 -0400 Subject: [PATCH 08/14] simplify NewPeer in localPeerManager --- service/tbc/tbc.go | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/service/tbc/tbc.go b/service/tbc/tbc.go index 5c242455..5ae75d50 100644 --- a/service/tbc/tbc.go +++ b/service/tbc/tbc.go @@ -493,13 +493,7 @@ func (s *Server) localPeerManager(ctx context.Context) error { peersWanted := 1 peerC := make(chan string, peersWanted) - host, port, err := net.SplitHostPort(s.seeds[0]) - if err != nil { - return err - } - - address := net.JoinHostPort(host, port) - peer, err := NewPeer(s.wireNet, address) + peer, err := NewPeer(s.wireNet, s.seeds[0]) if err != nil { return fmt.Errorf("new peer: %w", err) } From 7b80763051a661c370583ddef66591ab1ba5d837 Mon Sep 17 00:00:00 2001 From: ClaytonNorthey92 Date: Tue, 25 Jun 2024 11:47:50 -0400 Subject: [PATCH 09/14] Update cmd/tbcd/tbcd.go Co-authored-by: Joshua Sing --- cmd/tbcd/tbcd.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/tbcd/tbcd.go b/cmd/tbcd/tbcd.go index ff917526..6aa50d5d 100644 --- a/cmd/tbcd/tbcd.go +++ b/cmd/tbcd/tbcd.go @@ -96,7 +96,7 @@ var ( "TBC_SEEDS": config.Config{ Value: &cfg.Seeds, DefaultValue: []string{}, - Help: "list of tbc seeds, format of :", + Help: "list of seed domains for Bitcoin P2P, in the format ':' (for localnet, must be a single host:port)", Print: config.PrintAll, }, } From ebe4ed01a598f23195813af6207b0615df7bab5d Mon Sep 17 00:00:00 2001 From: ClaytonNorthey92 Date: Tue, 25 Jun 2024 12:00:43 -0400 Subject: [PATCH 10/14] use AppendSlice --- config/config.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config/config.go b/config/config.go index 9a2d05b7..473447b5 100644 --- a/config/config.go +++ b/config/config.go @@ -90,7 +90,8 @@ func Parse(c CfgMap) error { reflect.ValueOf(v.Value).Elem().SetBool(val) case reflect.Slice: - *(v.Value.(*[]string)) = strings.Split(envValue, ",") + // we assume that the slice here can be appended to (ex. an empty slice) + reflect.AppendSlice(reflect.ValueOf(v.Value), reflect.ValueOf(strings.Split(envValue, ","))) default: return fmt.Errorf("unsuported type for %v: %v", From 9f5fdd6d44e6212037dcedcd58e3a6240029bc19 Mon Sep 17 00:00:00 2001 From: ClaytonNorthey92 Date: Tue, 25 Jun 2024 12:34:00 -0400 Subject: [PATCH 11/14] removed ports from variables --- service/tbc/tbc.go | 26 +++++++++++--------------- service/tbc/tbc_test.go | 4 ++-- service/tbc/tbcfork_test.go | 2 +- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/service/tbc/tbc.go b/service/tbc/tbc.go index 5ae75d50..a37fc970 100644 --- a/service/tbc/tbc.go +++ b/service/tbc/tbc.go @@ -48,10 +48,6 @@ const ( promSubsystem = "tbc_service" // Prometheus - mainnetPort = "8333" - testnetPort = "18333" - localnetPort = "18444" - defaultPeersWanted = 64 defaultPendingBlocks = 128 // 128 * ~4MB max memory use @@ -68,21 +64,21 @@ var ( zeroHash = new(chainhash.Hash) // used to check if a hash is invalid localnetSeeds = []string{ - fmt.Sprintf("bitcoind:%s", localnetPort), + "bitcoind:18444", } testnetSeeds = []string{ - fmt.Sprintf("testnet-seed.bitcoin.jonasschnelli.ch:%s", testnetPort), - fmt.Sprintf("seed.tbtc.petertodd.org:%s", testnetPort), - fmt.Sprintf("seed.testnet.bitcoin.sprovoost.nl:%s", testnetPort), - fmt.Sprintf("testnet-seed.bluematt.me:%s", testnetPort), + "testnet-seed.bitcoin.jonasschnelli.ch:18333", + "seed.tbtc.petertodd.org:18333", + "seed.testnet.bitcoin.sprovoost.nl:18333", + "testnet-seed.bluematt.me:18333", } mainnetSeeds = []string{ - fmt.Sprintf("seed.bitcoin.sipa.be:%s", mainnetPort), - fmt.Sprintf("dnsseed.bluematt.me:%s", mainnetPort), - fmt.Sprintf("dnsseed.bitcoin.dashjr.org:%s", mainnetPort), - fmt.Sprintf("seed.bitcoinstats.com:%s", mainnetPort), - fmt.Sprintf("seed.bitnodes.io:%s", mainnetPort), - fmt.Sprintf("seed.bitcoin.jonasschnelli.ch:%s", mainnetPort), + "seed.bitcoin.sipa.be:8333", + "dnsseed.bluematt.me:8333", + "dnsseed.bitcoin.dashjr.org:8333", + "seed.bitcoinstats.com:8333", + "seed.bitnodes.io:8333", + "seed.bitcoin.jonasschnelli.ch:8333", } ) diff --git a/service/tbc/tbc_test.go b/service/tbc/tbc_test.go index 85e473cf..f0cd8787 100644 --- a/service/tbc/tbc_test.go +++ b/service/tbc/tbc_test.go @@ -821,7 +821,7 @@ func createTbcServer(ctx context.Context, t *testing.T, mappedPeerPort nat.Port) cfg.LevelDBHome = home cfg.Network = networkLocalnet cfg.ListenAddress = tcbListenAddress - cfg.Seeds = []string{fmt.Sprintf("127.0.0.1:%s", localnetPort)} + cfg.Seeds = []string{"127.0.0.1:18444"} tbcServer, err := NewServer(cfg) if err != nil { t.Fatal(err) @@ -1033,5 +1033,5 @@ func createBitcoindWithInitialBlocks(ctx context.Context, t *testing.T, blocks u t.Fatal(err) } - return bitcoindContainer, nat.Port(localnetPort) + return bitcoindContainer, nat.Port("18444") } diff --git a/service/tbc/tbcfork_test.go b/service/tbc/tbcfork_test.go index 4fdbfea3..aac606c2 100644 --- a/service/tbc/tbcfork_test.go +++ b/service/tbc/tbcfork_test.go @@ -534,7 +534,7 @@ func TestFork(t *testing.T) { Network: networkLocalnet, PeersWanted: 1, PrometheusListenAddress: "", - Seeds: []string{fmt.Sprintf("127.0.0.1:%s", localnetPort)}, + Seeds: []string{"127.0.0.1:18444"}, } _ = loggo.ConfigureLoggers(cfg.LogLevel) s, err := NewServer(cfg) From 6c861ea8165c065d2d9a23cef05a110941a7a783 Mon Sep 17 00:00:00 2001 From: ClaytonNorthey92 Date: Tue, 25 Jun 2024 13:09:33 -0400 Subject: [PATCH 12/14] fix reflect handling of seeds --- config/config.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config/config.go b/config/config.go index 473447b5..f77a78ab 100644 --- a/config/config.go +++ b/config/config.go @@ -91,7 +91,8 @@ func Parse(c CfgMap) error { reflect.ValueOf(v.Value).Elem().SetBool(val) case reflect.Slice: // we assume that the slice here can be appended to (ex. an empty slice) - reflect.AppendSlice(reflect.ValueOf(v.Value), reflect.ValueOf(strings.Split(envValue, ","))) + value := reflect.ValueOf(v.Value).Elem() + value.Set(reflect.AppendSlice(value, reflect.ValueOf(strings.Split(envValue, ",")))) default: return fmt.Errorf("unsuported type for %v: %v", From 9d43d0027ba616de7cde7ca05d5b0e5bed7fd1e9 Mon Sep 17 00:00:00 2001 From: ClaytonNorthey92 Date: Wed, 26 Jun 2024 09:29:01 -0400 Subject: [PATCH 13/14] Update config/config.go Co-authored-by: Joshua Sing --- config/config.go | 1 - 1 file changed, 1 deletion(-) diff --git a/config/config.go b/config/config.go index f77a78ab..2f71ab9d 100644 --- a/config/config.go +++ b/config/config.go @@ -90,7 +90,6 @@ func Parse(c CfgMap) error { reflect.ValueOf(v.Value).Elem().SetBool(val) case reflect.Slice: - // we assume that the slice here can be appended to (ex. an empty slice) value := reflect.ValueOf(v.Value).Elem() value.Set(reflect.AppendSlice(value, reflect.ValueOf(strings.Split(envValue, ",")))) From 493fd9726b6f5f7d07a6b9c7460f453d06e59190 Mon Sep 17 00:00:00 2001 From: ClaytonNorthey92 Date: Wed, 26 Jun 2024 09:55:01 -0400 Subject: [PATCH 14/14] using 127.0.0.1 as default IP/host for localnet --- service/tbc/tbc.go | 2 +- service/tbc/tbc_test.go | 1 - service/tbc/tbcfork_test.go | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/service/tbc/tbc.go b/service/tbc/tbc.go index a37fc970..da8f9222 100644 --- a/service/tbc/tbc.go +++ b/service/tbc/tbc.go @@ -64,7 +64,7 @@ var ( zeroHash = new(chainhash.Hash) // used to check if a hash is invalid localnetSeeds = []string{ - "bitcoind:18444", + "127.0.0.1:18444", } testnetSeeds = []string{ "testnet-seed.bitcoin.jonasschnelli.ch:18333", diff --git a/service/tbc/tbc_test.go b/service/tbc/tbc_test.go index f0cd8787..d4f143c8 100644 --- a/service/tbc/tbc_test.go +++ b/service/tbc/tbc_test.go @@ -821,7 +821,6 @@ func createTbcServer(ctx context.Context, t *testing.T, mappedPeerPort nat.Port) cfg.LevelDBHome = home cfg.Network = networkLocalnet cfg.ListenAddress = tcbListenAddress - cfg.Seeds = []string{"127.0.0.1:18444"} tbcServer, err := NewServer(cfg) if err != nil { t.Fatal(err) diff --git a/service/tbc/tbcfork_test.go b/service/tbc/tbcfork_test.go index aac606c2..9b3c5da5 100644 --- a/service/tbc/tbcfork_test.go +++ b/service/tbc/tbcfork_test.go @@ -534,7 +534,6 @@ func TestFork(t *testing.T) { Network: networkLocalnet, PeersWanted: 1, PrometheusListenAddress: "", - Seeds: []string{"127.0.0.1:18444"}, } _ = loggo.ConfigureLoggers(cfg.LogLevel) s, err := NewServer(cfg)