15
15
package chainsync
16
16
17
17
import (
18
+ "encoding/hex"
19
+ "strconv"
20
+ "strings"
21
+
18
22
"github.com/blinklabs-io/snek/plugin"
23
+
24
+ ocommon "github.com/blinklabs-io/gouroboros/protocol/common"
19
25
)
20
26
21
27
var cmdlineOptions struct {
@@ -24,6 +30,7 @@ var cmdlineOptions struct {
24
30
address string
25
31
socketPath string
26
32
ntcTcp bool
33
+ bulkMode bool
27
34
intersectTip bool
28
35
intersectPoint string
29
36
includeCbor bool
@@ -74,14 +81,27 @@ func init() {
74
81
DefaultValue : false ,
75
82
Dest : & (cmdlineOptions .ntcTcp ),
76
83
},
84
+ {
85
+ Name : "bulk-mode" ,
86
+ Type : plugin .PluginOptionTypeBool ,
87
+ Description : "use the 'bulk' sync mode with NtN (node-to-node). This should only be used against your own nodes for resource usage reasons" ,
88
+ DefaultValue : false ,
89
+ Dest : & (cmdlineOptions .bulkMode ),
90
+ },
77
91
{
78
92
Name : "intersect-tip" ,
79
93
Type : plugin .PluginOptionTypeBool ,
80
94
Description : "start syncing at the chain tip (defaults to chain genesis)" ,
81
95
DefaultValue : true ,
82
96
Dest : & (cmdlineOptions .intersectTip ),
83
97
},
84
- // TODO: intersect-point
98
+ {
99
+ Name : "intersect-point" ,
100
+ Type : plugin .PluginOptionTypeString ,
101
+ Description : "start syncing at the specified chain point(s) in '<slot>.<hash>' format" ,
102
+ DefaultValue : "" ,
103
+ Dest : & (cmdlineOptions .intersectPoint ),
104
+ },
85
105
{
86
106
Name : "include-cbor" ,
87
107
Type : plugin .PluginOptionTypeBool ,
@@ -95,15 +115,48 @@ func init() {
95
115
}
96
116
97
117
func NewFromCmdlineOptions () plugin.Plugin {
98
- p := New (
118
+ opts := [] ChainSyncOptionFunc {
99
119
WithNetwork (cmdlineOptions .network ),
100
120
WithNetworkMagic (uint32 (cmdlineOptions .networkMagic )),
101
121
WithAddress (cmdlineOptions .address ),
102
122
WithSocketPath (cmdlineOptions .socketPath ),
103
123
WithNtcTcp (cmdlineOptions .ntcTcp ),
104
- WithIntersectTip (cmdlineOptions .intersectTip ),
105
- // TODO: WithIntersectPoints
124
+ WithBulkMode (cmdlineOptions .bulkMode ),
106
125
WithIncludeCbor (cmdlineOptions .includeCbor ),
107
- )
126
+ }
127
+ if cmdlineOptions .intersectPoint != "" {
128
+ intersectPoints := []ocommon.Point {}
129
+ for _ , point := range strings .Split (cmdlineOptions .intersectPoint , "," ) {
130
+ intersectPointParts := strings .Split (point , "." )
131
+ if len (intersectPointParts ) != 2 {
132
+ panic ("invalid intersect point format" )
133
+ }
134
+ intersectSlot , err := strconv .ParseUint (intersectPointParts [0 ], 10 , 64 )
135
+ if err != nil {
136
+ panic ("invalid intersect point format" )
137
+ }
138
+ intersectHashBytes , err := hex .DecodeString (intersectPointParts [1 ])
139
+ if err != nil {
140
+ panic ("invalid intersect point format" )
141
+ }
142
+ intersectPoints = append (
143
+ intersectPoints ,
144
+ ocommon.Point {
145
+ Slot : intersectSlot ,
146
+ Hash : intersectHashBytes [:],
147
+ },
148
+ )
149
+ }
150
+ opts = append (
151
+ opts ,
152
+ WithIntersectPoints (intersectPoints ),
153
+ )
154
+ } else {
155
+ opts = append (
156
+ opts ,
157
+ WithIntersectTip (cmdlineOptions .intersectTip ),
158
+ )
159
+ }
160
+ p := New (opts ... )
108
161
return p
109
162
}
0 commit comments