From 38af045ab12e1c2fc3bac9abfe224fe68fdb48e5 Mon Sep 17 00:00:00 2001 From: Boris Nagaev Date: Thu, 21 Nov 2024 12:47:26 -0300 Subject: [PATCH] wire: add bitcoin network magic for default SigNet Added constant wire.SigNet, added it to stringer for BitcoinNet type. Added a test in chaincfg to compare calculated magic value with the constant. --- chaincfg/params_test.go | 9 +++++++++ wire/doc.go | 1 + wire/protocol.go | 7 ++++++- wire/protocol_test.go | 1 + 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/chaincfg/params_test.go b/chaincfg/params_test.go index 4166ce0a..4d3f4d22 100644 --- a/chaincfg/params_test.go +++ b/chaincfg/params_test.go @@ -9,6 +9,9 @@ import ( "encoding/hex" "math/big" "testing" + + "github.com/btcsuite/btcd/wire" + "github.com/stretchr/testify/require" ) // TestInvalidHashStr ensures the newShaHashFromStr function panics when used to @@ -104,6 +107,12 @@ func TestSigNetPowLimit(t *testing.T) { } } +// TestSigNetMagic makes sure that the default signet has the expected bitcoin +// network magic. +func TestSigNetMagic(t *testing.T) { + require.Equal(t, wire.SigNet, SigNetParams.Net) +} + // compactToBig is a copy of the blockchain.CompactToBig function. We copy it // here so we don't run into a circular dependency just because of a test. func compactToBig(compact uint32) *big.Int { diff --git a/wire/doc.go b/wire/doc.go index 5e03ff20..e05bb935 100644 --- a/wire/doc.go +++ b/wire/doc.go @@ -86,6 +86,7 @@ the following constants: wire.MainNet wire.TestNet (Regression test network) wire.TestNet3 (Test network version 3) + wire.SigNet (Signet, default) wire.SimNet (Simulation test network) # Determining Message Type diff --git a/wire/protocol.go b/wire/protocol.go index e1344f3a..26d74bb6 100644 --- a/wire/protocol.go +++ b/wire/protocol.go @@ -169,7 +169,7 @@ func (f ServiceFlag) String() string { // BitcoinNet represents which bitcoin network a message belongs to. type BitcoinNet uint32 -// Constants used to indicate the message bitcoin network. They can also be +// Constants used to indicate the message bitcoin network. They can also be // used to seek to the next message when a stream's state is unknown, but // this package does not provide that functionality since it's generally a // better idea to simply disconnect clients that are misbehaving over TCP. @@ -183,6 +183,10 @@ const ( // TestNet3 represents the test network (version 3). TestNet3 BitcoinNet = 0x0709110b + // SigNet represents the public default SigNet. For custom signets, + // see CustomSignetParams. + SigNet BitcoinNet = 0x40CF030A + // SimNet represents the simulation test network. SimNet BitcoinNet = 0x12141c16 ) @@ -193,6 +197,7 @@ var bnStrings = map[BitcoinNet]string{ MainNet: "MainNet", TestNet: "TestNet", TestNet3: "TestNet3", + SigNet: "SigNet", SimNet: "SimNet", } diff --git a/wire/protocol_test.go b/wire/protocol_test.go index eeeffb60..5ab5b9dd 100644 --- a/wire/protocol_test.go +++ b/wire/protocol_test.go @@ -49,6 +49,7 @@ func TestBitcoinNetStringer(t *testing.T) { {MainNet, "MainNet"}, {TestNet, "TestNet"}, {TestNet3, "TestNet3"}, + {SigNet, "SigNet"}, {SimNet, "SimNet"}, {0xffffffff, "Unknown BitcoinNet (4294967295)"}, }