@@ -9,8 +9,10 @@ import (
99 "encoding/hex"
1010 "fmt"
1111 "math/big"
12+ "net/url"
1213 "os"
1314 "os/signal"
15+ "strings"
1416 "syscall"
1517)
1618
@@ -60,8 +62,8 @@ func newBlockdag(dbPath string) (nakamoto.BlockDAG, nakamoto.ConsensusConfig, *s
6062 copy (genesisBlockHash [:], genesisBlockHash_ )
6163
6264 conf := nakamoto.ConsensusConfig {
63- EpochLengthBlocks : 5 ,
64- TargetEpochLengthMillis : 2000 ,
65+ EpochLengthBlocks : 200 ,
66+ TargetEpochLengthMillis : 1000 * 60 * 5 , // 5 minutes
6567 GenesisDifficulty : * genesis_difficulty ,
6668 GenesisBlockHash : genesisBlockHash ,
6769 MaxBlockSizeBytes : 2 * 1024 * 1024 , // 2MB
@@ -78,6 +80,7 @@ func newBlockdag(dbPath string) (nakamoto.BlockDAG, nakamoto.ConsensusConfig, *s
7880func RunNode (cmdCtx * cli.Context ) (error ) {
7981 port := cmdCtx .String ("port" )
8082 dbPath := cmdCtx .String ("db" )
83+ bootstrapPeers := cmdCtx .String ("peers" )
8184
8285 // DAG.
8386 dag , _ , _ := newBlockdag (dbPath )
@@ -108,8 +111,23 @@ func RunNode(cmdCtx *cli.Context) (error) {
108111 os .Exit (1 )
109112 }()
110113
111- node .Start ()
114+ // Bootstrap the node.
115+ if bootstrapPeers != "" {
116+ peerAddresses := []string {}
117+ // Split the comma-separated list of peer addresses.
118+ peerlist := strings .Split (bootstrapPeers , "," )
119+ for _ , peerAddress := range peerlist {
120+ // Validate URL.
121+ _ , err := url .ParseRequestURI (peerAddress )
122+ if err != nil {
123+ return fmt .Errorf ("Invalid peer address: %s" , peerAddress )
124+ }
125+ peerAddresses = append (peerAddresses , peerAddress )
126+ }
127+
128+ node .Peer .Bootstrap (peerAddresses )
129+ }
112130
113-
131+ node . Start ()
114132 return nil
115133}
0 commit comments