mirror of
https://github.com/aljazceru/ark.git
synced 2025-12-17 20:24:21 +01:00
arkd: support signet (#251)
* pass MutinyNet parameters * set signetblocktime=30 * supports signet in client and sdk * ark: --network help message to support signet * revert intialPeers set
This commit is contained in:
@@ -18,6 +18,7 @@ var explorerUrls = map[string]string{
|
||||
common.Bitcoin.Name: "https://blockstream.info/api",
|
||||
common.BitcoinTestNet.Name: "https://blockstream.info/testnet/api",
|
||||
common.BitcoinRegTest.Name: "http://localhost:3000",
|
||||
common.BitcoinSigNet.Name: "https://mutinynet.com/api",
|
||||
}
|
||||
|
||||
func (c *clArkBitcoinCLI) Init(ctx *cli.Context) error {
|
||||
@@ -31,7 +32,7 @@ func (c *clArkBitcoinCLI) Init(ctx *cli.Context) error {
|
||||
if len(url) <= 0 {
|
||||
return fmt.Errorf("invalid ark url")
|
||||
}
|
||||
if net != common.Bitcoin.Name && net != common.BitcoinTestNet.Name && net != common.BitcoinRegTest.Name {
|
||||
if net != common.Bitcoin.Name && net != common.BitcoinTestNet.Name && net != common.BitcoinRegTest.Name && net != common.BitcoinSigNet.Name {
|
||||
return fmt.Errorf("invalid network")
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,9 @@ import (
|
||||
)
|
||||
|
||||
func toChainParams(net *common.Network) chaincfg.Params {
|
||||
// we pass nil to have the equivalent of dnssec=0 in bitcoin.conf
|
||||
mutinyNetSigNetParams := chaincfg.CustomSignetParams(common.MutinyNetChallenge, nil)
|
||||
mutinyNetSigNetParams.TargetTimePerBlock = common.MutinyNetBlockTime
|
||||
switch net.Name {
|
||||
case common.Bitcoin.Name:
|
||||
return chaincfg.MainNetParams
|
||||
@@ -13,6 +16,8 @@ func toChainParams(net *common.Network) chaincfg.Params {
|
||||
return chaincfg.TestNet3Params
|
||||
case common.BitcoinRegTest.Name:
|
||||
return chaincfg.RegressionNetParams
|
||||
case common.BitcoinSigNet.Name:
|
||||
return mutinyNetSigNetParams
|
||||
default:
|
||||
return chaincfg.MainNetParams
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ var (
|
||||
}
|
||||
NetworkFlag = cli.StringFlag{
|
||||
Name: "network",
|
||||
Usage: "network to use (liquid, testnet, regtest)",
|
||||
Usage: "network to use (liquid, testnet, regtest, signet)",
|
||||
Value: "liquid",
|
||||
}
|
||||
UrlFlag = cli.StringFlag{
|
||||
|
||||
@@ -212,7 +212,7 @@ func getCLI(networkName string) (interfaces.CLI, error) {
|
||||
switch networkName {
|
||||
case common.Liquid.Name, common.LiquidTestNet.Name, common.LiquidRegTest.Name:
|
||||
return covenant.New(), nil
|
||||
case common.Bitcoin.Name, common.BitcoinTestNet.Name, common.BitcoinRegTest.Name:
|
||||
case common.Bitcoin.Name, common.BitcoinTestNet.Name, common.BitcoinRegTest.Name, common.BitcoinSigNet.Name:
|
||||
return covenantless.New(), nil
|
||||
default:
|
||||
return nil, fmt.Errorf("unknown network (%s)", networkName)
|
||||
|
||||
@@ -239,6 +239,8 @@ func networkFromString(net string) *common.Network {
|
||||
return &common.BitcoinTestNet
|
||||
case common.BitcoinRegTest.Name:
|
||||
return &common.BitcoinRegTest
|
||||
case common.BitcoinSigNet.Name:
|
||||
return &common.BitcoinSigNet
|
||||
default:
|
||||
panic(fmt.Sprintf("unknown network (%s)", net))
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package common
|
||||
|
||||
import "strings"
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Network struct {
|
||||
Name string
|
||||
@@ -37,6 +40,20 @@ var BitcoinRegTest = Network{
|
||||
Addr: BitcoinTestNet.Addr,
|
||||
}
|
||||
|
||||
var BitcoinSigNet = Network{
|
||||
Name: "signet",
|
||||
Addr: BitcoinTestNet.Addr,
|
||||
}
|
||||
|
||||
var MutinyNetChallenge = []byte{
|
||||
0x51, 0x21, 0x02, 0xf7, 0x56, 0x1d, 0x20, 0x8d, 0xd9, 0xae, 0x99, 0xbf,
|
||||
0x49, 0x72, 0x73, 0xe1, 0x6f, 0x38, 0x9b, 0xdb, 0xd6, 0xc4, 0x74, 0x2d,
|
||||
0xdb, 0x8e, 0x6b, 0x21, 0x6e, 0x64, 0xfa, 0x29, 0x28, 0xad, 0x8f, 0x51,
|
||||
0xae,
|
||||
}
|
||||
|
||||
const MutinyNetBlockTime = time.Second * 30
|
||||
|
||||
func IsLiquid(network Network) bool {
|
||||
return strings.Contains(network.Name, "liquid")
|
||||
}
|
||||
|
||||
@@ -105,6 +105,8 @@ func NetworkFromString(net string) common.Network {
|
||||
return common.BitcoinTestNet
|
||||
case common.BitcoinRegTest.Name:
|
||||
return common.BitcoinRegTest
|
||||
case common.BitcoinSigNet.Name:
|
||||
return common.BitcoinSigNet
|
||||
case common.Bitcoin.Name:
|
||||
fallthrough
|
||||
default:
|
||||
@@ -126,6 +128,8 @@ func ToElementsNetwork(net common.Network) network.Network {
|
||||
}
|
||||
|
||||
func ToBitcoinNetwork(net common.Network) chaincfg.Params {
|
||||
mutinyNetSigNetParams := chaincfg.CustomSignetParams(common.MutinyNetChallenge, nil)
|
||||
mutinyNetSigNetParams.TargetTimePerBlock = common.MutinyNetBlockTime
|
||||
switch net.Name {
|
||||
case common.Bitcoin.Name:
|
||||
return chaincfg.MainNetParams
|
||||
@@ -133,6 +137,8 @@ func ToBitcoinNetwork(net common.Network) chaincfg.Params {
|
||||
return chaincfg.TestNet3Params
|
||||
case common.BitcoinRegTest.Name:
|
||||
return chaincfg.RegressionNetParams
|
||||
case common.BitcoinSigNet.Name:
|
||||
return mutinyNetSigNetParams
|
||||
default:
|
||||
return chaincfg.MainNetParams
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ var (
|
||||
common.Bitcoin.Name: "https://blockstream.info/api",
|
||||
common.BitcoinTestNet.Name: "https://blockstream.info/testnet/api",
|
||||
common.BitcoinRegTest.Name: "http://localhost:3000",
|
||||
common.BitcoinSigNet.Name: "https://mutinynet.com/api",
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
2
server/.gitignore
vendored
2
server/.gitignore
vendored
@@ -24,3 +24,5 @@ go.work
|
||||
go.work.sum
|
||||
|
||||
.vscode/
|
||||
|
||||
tmp/
|
||||
@@ -1,4 +1,4 @@
|
||||
.PHONY: build clean cov help intergrationtest lint run test vet proto proto-lint
|
||||
.PHONY: build clean cov help intergrationtest lint run run-signet test vet proto proto-lint
|
||||
|
||||
## build: build for all platforms
|
||||
build:
|
||||
@@ -30,7 +30,7 @@ lint:
|
||||
@echo "Linting code..."
|
||||
@golangci-lint run --fix
|
||||
|
||||
## run: run in dev mode
|
||||
## run: run in regtest mode
|
||||
run: clean
|
||||
@echo "Running arkd in dev mode..."
|
||||
@export ARK_NEUTRINO_PEER=localhost:18444; \
|
||||
@@ -45,6 +45,24 @@ run: clean
|
||||
export ARK_MIN_RELAY_FEE=200; \
|
||||
go run ./cmd/arkd
|
||||
|
||||
## export ARK_NEUTRINO_PEER=44.240.54.180:38333 ; \
|
||||
|
||||
## run: run in signet mode
|
||||
run-signet: clean
|
||||
@echo "Running arkd in signet mode..."
|
||||
@export ARK_ROUND_INTERVAL=10; \
|
||||
export ARK_LOG_LEVEL=5; \
|
||||
export ARK_NETWORK=signet; \
|
||||
export ARK_PORT=7070; \
|
||||
export ARK_NO_TLS=true; \
|
||||
export ARK_NO_MACAROONS=true; \
|
||||
export ARK_TX_BUILDER_TYPE=covenantless; \
|
||||
export ARK_ESPLORA_URL=https://mutinynet.com/api; \
|
||||
export ARK_NEUTRINO_PEER=45.79.52.207:38333; \
|
||||
export ARK_MIN_RELAY_FEE=200; \
|
||||
export ARK_DATADIR=./tmp/signet/arkd-data; \
|
||||
go run ./cmd/arkd
|
||||
|
||||
## test: runs unit and component tests
|
||||
test:
|
||||
@echo "Running unit tests..."
|
||||
|
||||
@@ -41,6 +41,7 @@ var (
|
||||
common.Bitcoin.Name: {},
|
||||
common.BitcoinTestNet.Name: {},
|
||||
common.BitcoinRegTest.Name: {},
|
||||
common.BitcoinSigNet.Name: {},
|
||||
common.Liquid.Name: {},
|
||||
common.LiquidTestNet.Name: {},
|
||||
common.LiquidRegTest.Name: {},
|
||||
|
||||
@@ -101,7 +101,7 @@ func LoadConfig() (*Config, error) {
|
||||
|
||||
net, err := getNetwork()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("error while getting network: %s", err)
|
||||
}
|
||||
|
||||
if err := initDatadir(); err != nil {
|
||||
@@ -160,6 +160,8 @@ func getNetwork() (common.Network, error) {
|
||||
return common.BitcoinTestNet, nil
|
||||
case common.BitcoinRegTest.Name:
|
||||
return common.BitcoinRegTest, nil
|
||||
case common.BitcoinSigNet.Name:
|
||||
return common.BitcoinSigNet, nil
|
||||
default:
|
||||
return common.Network{}, fmt.Errorf("unknown network %s", viper.GetString(Network))
|
||||
}
|
||||
|
||||
@@ -1010,6 +1010,8 @@ func (b *txBuilder) getTaprootPreimage(tx string, inputIndex int, leafScript []b
|
||||
}
|
||||
|
||||
func (b *txBuilder) onchainNetwork() *chaincfg.Params {
|
||||
mutinyNetSigNetParams := chaincfg.CustomSignetParams(common.MutinyNetChallenge, nil)
|
||||
mutinyNetSigNetParams.TargetTimePerBlock = common.MutinyNetBlockTime
|
||||
switch b.net.Name {
|
||||
case common.Bitcoin.Name:
|
||||
return &chaincfg.MainNetParams
|
||||
@@ -1017,6 +1019,8 @@ func (b *txBuilder) onchainNetwork() *chaincfg.Params {
|
||||
return &chaincfg.TestNet3Params
|
||||
case common.BitcoinRegTest.Name:
|
||||
return &chaincfg.RegressionNetParams
|
||||
case common.BitcoinSigNet.Name:
|
||||
return &mutinyNetSigNetParams
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -43,6 +43,8 @@ type WalletConfig struct {
|
||||
}
|
||||
|
||||
func (c WalletConfig) chainParams() *chaincfg.Params {
|
||||
mutinyNetSigNetParams := chaincfg.CustomSignetParams(common.MutinyNetChallenge, nil)
|
||||
mutinyNetSigNetParams.TargetTimePerBlock = common.MutinyNetBlockTime
|
||||
switch c.Network.Name {
|
||||
case common.Bitcoin.Name:
|
||||
return &chaincfg.MainNetParams
|
||||
@@ -50,6 +52,8 @@ func (c WalletConfig) chainParams() *chaincfg.Params {
|
||||
return &chaincfg.TestNet3Params
|
||||
case common.BitcoinRegTest.Name:
|
||||
return &chaincfg.RegressionNetParams
|
||||
case common.BitcoinSigNet.Name:
|
||||
return &mutinyNetSigNetParams
|
||||
default:
|
||||
return &chaincfg.MainNetParams
|
||||
}
|
||||
@@ -191,7 +195,7 @@ func (s *service) Unlock(_ context.Context, password string) error {
|
||||
CoinSelectionStrategy: wallet.CoinSelectionLargest,
|
||||
ChainSource: s.chainSource,
|
||||
}
|
||||
blockCache := blockcache.NewBlockCache(20 * 1024 * 1024)
|
||||
blockCache := blockcache.NewBlockCache(2 * 1024 * 1024 * 1024)
|
||||
|
||||
wallet, err := btcwallet.New(config, blockCache)
|
||||
if err != nil {
|
||||
@@ -204,7 +208,7 @@ func (s *service) Unlock(_ context.Context, password string) error {
|
||||
|
||||
for {
|
||||
if !wallet.InternalWallet().ChainSynced() {
|
||||
log.Debug("waiting sync....")
|
||||
log.Debugf("waiting sync: current height %d", wallet.InternalWallet().Manager.SyncedTo().Height)
|
||||
time.Sleep(3 * time.Second)
|
||||
continue
|
||||
}
|
||||
@@ -691,7 +695,7 @@ func (s *service) create(mnemonic, password string, addrGap uint32) error {
|
||||
CoinSelectionStrategy: wallet.CoinSelectionLargest,
|
||||
ChainSource: s.chainSource,
|
||||
}
|
||||
blockCache := blockcache.NewBlockCache(20 * 1024 * 1024)
|
||||
blockCache := blockcache.NewBlockCache(2 * 1024 * 1024 * 1024)
|
||||
|
||||
wallet, err := btcwallet.New(config, blockCache)
|
||||
if err != nil {
|
||||
@@ -707,7 +711,7 @@ func (s *service) create(mnemonic, password string, addrGap uint32) error {
|
||||
|
||||
for {
|
||||
if !wallet.InternalWallet().ChainSynced() {
|
||||
log.Debug("waiting sync....")
|
||||
log.Debugf("waiting sync: current height %d", wallet.InternalWallet().Manager.SyncedTo().Height)
|
||||
time.Sleep(3 * time.Second)
|
||||
continue
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user