@blinklabs/dingo 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (195) hide show
  1. package/.dockerignore +5 -0
  2. package/.github/CODEOWNERS +5 -0
  3. package/.github/assets/dingo-ate-my-blockchain.png +0 -0
  4. package/.github/assets/dingo-illustration.png +0 -0
  5. package/.github/assets/dingo-logo-with-text-horizontal.png +0 -0
  6. package/.github/assets/dingo-logo-with-text.png +0 -0
  7. package/.github/dependabot.yml +19 -0
  8. package/.github/dingo-20241210.png +0 -0
  9. package/.github/dingo.md +56 -0
  10. package/.github/workflows/ci-docker.yml +36 -0
  11. package/.github/workflows/conventional-commits.yml +17 -0
  12. package/.github/workflows/go-test.yml +29 -0
  13. package/.github/workflows/golangci-lint.yml +23 -0
  14. package/.github/workflows/publish.yml +207 -0
  15. package/.golangci.yml +71 -0
  16. package/Dockerfile +25 -0
  17. package/LICENSE +201 -0
  18. package/Makefile +53 -0
  19. package/README.md +150 -0
  20. package/blockfetch.go +144 -0
  21. package/chain/chain.go +504 -0
  22. package/chain/chain_test.go +468 -0
  23. package/chain/errors.go +80 -0
  24. package/chain/event.go +33 -0
  25. package/chain/iter.go +64 -0
  26. package/chainsync/chainsync.go +97 -0
  27. package/chainsync.go +223 -0
  28. package/cmd/dingo/load.go +52 -0
  29. package/cmd/dingo/main.go +118 -0
  30. package/cmd/dingo/serve.go +49 -0
  31. package/config/cardano/node.go +192 -0
  32. package/config/cardano/node_test.go +85 -0
  33. package/config/cardano/preview/README.md +4 -0
  34. package/config/cardano/preview/alonzo-genesis.json +196 -0
  35. package/config/cardano/preview/byron-genesis.json +117 -0
  36. package/config/cardano/preview/config.json +114 -0
  37. package/config/cardano/preview/conway-genesis.json +297 -0
  38. package/config/cardano/preview/shelley-genesis.json +68 -0
  39. package/config.go +245 -0
  40. package/connmanager/connection_manager.go +105 -0
  41. package/connmanager/connection_manager_test.go +185 -0
  42. package/connmanager/event.go +37 -0
  43. package/connmanager/listener.go +140 -0
  44. package/connmanager/outbound.go +93 -0
  45. package/connmanager/socket.go +55 -0
  46. package/connmanager/unix.go +78 -0
  47. package/custom-p2p-topology.json +24 -0
  48. package/custom-p2p-topology.json.backup +24 -0
  49. package/custom-p2p-topology.json.mainnet +37 -0
  50. package/database/account.go +138 -0
  51. package/database/block.go +362 -0
  52. package/database/certs.go +53 -0
  53. package/database/commit_timestamp.go +77 -0
  54. package/database/database.go +118 -0
  55. package/database/database_test.go +62 -0
  56. package/database/drep.go +27 -0
  57. package/database/epoch.go +121 -0
  58. package/database/immutable/chunk.go +182 -0
  59. package/database/immutable/immutable.go +350 -0
  60. package/database/immutable/immutable_test.go +59 -0
  61. package/database/immutable/primary.go +106 -0
  62. package/database/immutable/secondary.go +103 -0
  63. package/database/immutable/testdata/08893.chunk +0 -0
  64. package/database/immutable/testdata/08893.primary +0 -0
  65. package/database/immutable/testdata/08893.secondary +0 -0
  66. package/database/immutable/testdata/08894.chunk +0 -0
  67. package/database/immutable/testdata/08894.primary +0 -0
  68. package/database/immutable/testdata/08894.secondary +0 -0
  69. package/database/immutable/testdata/README.md +4 -0
  70. package/database/plugin/blob/badger/commit_timestamp.go +50 -0
  71. package/database/plugin/blob/badger/database.go +152 -0
  72. package/database/plugin/blob/badger/logger.go +63 -0
  73. package/database/plugin/blob/badger/metrics.go +98 -0
  74. package/database/plugin/blob/blob.go +19 -0
  75. package/database/plugin/blob/store.go +40 -0
  76. package/database/plugin/log.go +27 -0
  77. package/database/plugin/metadata/metadata.go +19 -0
  78. package/database/plugin/metadata/sqlite/account.go +224 -0
  79. package/database/plugin/metadata/sqlite/certs.go +58 -0
  80. package/database/plugin/metadata/sqlite/commit_timestamp.go +68 -0
  81. package/database/plugin/metadata/sqlite/database.go +218 -0
  82. package/database/plugin/metadata/sqlite/epoch.go +120 -0
  83. package/database/plugin/metadata/sqlite/models/account.go +81 -0
  84. package/database/plugin/metadata/sqlite/models/auth_committee_hot.go +26 -0
  85. package/database/plugin/metadata/sqlite/models/deregistration_drep.go +26 -0
  86. package/database/plugin/metadata/sqlite/models/drep.go +27 -0
  87. package/database/plugin/metadata/sqlite/models/epoch.go +31 -0
  88. package/database/plugin/metadata/sqlite/models/models.go +45 -0
  89. package/database/plugin/metadata/sqlite/models/pool.go +97 -0
  90. package/database/plugin/metadata/sqlite/models/pparam_update.go +27 -0
  91. package/database/plugin/metadata/sqlite/models/pparams.go +27 -0
  92. package/database/plugin/metadata/sqlite/models/registration_drep.go +28 -0
  93. package/database/plugin/metadata/sqlite/models/resign_committee_cold.go +27 -0
  94. package/database/plugin/metadata/sqlite/models/stake_registration_delegation.go +27 -0
  95. package/database/plugin/metadata/sqlite/models/stake_vote_delegation.go +27 -0
  96. package/database/plugin/metadata/sqlite/models/stake_vote_registration_delegation.go +27 -0
  97. package/database/plugin/metadata/sqlite/models/tip.go +26 -0
  98. package/database/plugin/metadata/sqlite/models/update_drep.go +27 -0
  99. package/database/plugin/metadata/sqlite/models/utxo.go +30 -0
  100. package/database/plugin/metadata/sqlite/models/vote_delegation.go +26 -0
  101. package/database/plugin/metadata/sqlite/models/vote_registration_delegation.go +26 -0
  102. package/database/plugin/metadata/sqlite/pool.go +240 -0
  103. package/database/plugin/metadata/sqlite/pparams.go +110 -0
  104. package/database/plugin/metadata/sqlite/tip.go +83 -0
  105. package/database/plugin/metadata/sqlite/utxo.go +292 -0
  106. package/database/plugin/metadata/store.go +168 -0
  107. package/database/plugin/option.go +190 -0
  108. package/database/plugin/plugin.go +20 -0
  109. package/database/plugin/register.go +118 -0
  110. package/database/pparams.go +145 -0
  111. package/database/tip.go +45 -0
  112. package/database/txn.go +147 -0
  113. package/database/types/types.go +74 -0
  114. package/database/types/types_test.go +83 -0
  115. package/database/utxo.go +263 -0
  116. package/dist/artifacts.json +1 -0
  117. package/dist/checksums.txt +22 -0
  118. package/dist/config.yaml +253 -0
  119. package/dist/dingo-0.5.0-SNAPSHOT-d9431e4.tar.gz +0 -0
  120. package/dist/dingo-0.5.0-SNAPSHOT-d9431e4.tar.gz.sbom.json +1 -0
  121. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_darwin_arm64.tar.gz +0 -0
  122. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_darwin_arm64.tar.gz.sbom.json +1 -0
  123. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_darwin_x86_64.tar.gz +0 -0
  124. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_darwin_x86_64.tar.gz.sbom.json +1 -0
  125. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_amd64.apk +0 -0
  126. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_amd64.apk.sbom.json +1 -0
  127. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_amd64.deb +0 -0
  128. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_amd64.deb.sbom.json +1 -0
  129. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_amd64.rpm +0 -0
  130. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_amd64.rpm.sbom.json +1 -0
  131. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_arm64.apk +0 -0
  132. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_arm64.apk.sbom.json +1 -0
  133. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_arm64.deb +0 -0
  134. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_arm64.deb.sbom.json +1 -0
  135. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_arm64.rpm +0 -0
  136. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_arm64.rpm.sbom.json +1 -0
  137. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_arm64.tar.gz +0 -0
  138. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_arm64.tar.gz.sbom.json +1 -0
  139. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_x86_64.tar.gz +0 -0
  140. package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_x86_64.tar.gz.sbom.json +1 -0
  141. package/dist/dingo_darwin_amd64_v1/dingo +0 -0
  142. package/dist/dingo_darwin_arm64_v8.0/dingo +0 -0
  143. package/dist/dingo_linux_amd64_v1/dingo +0 -0
  144. package/dist/dingo_linux_arm64_v8.0/dingo +0 -0
  145. package/dist/homebrew/dingo.rb +51 -0
  146. package/dist/metadata.json +1 -0
  147. package/event/event.go +141 -0
  148. package/event/event_test.go +115 -0
  149. package/event/metrics.go +44 -0
  150. package/go.mod +98 -0
  151. package/go.sum +358 -0
  152. package/internal/config/config.go +145 -0
  153. package/internal/config/config_test.go +118 -0
  154. package/internal/node/load.go +149 -0
  155. package/internal/node/node.go +176 -0
  156. package/internal/version/version.go +33 -0
  157. package/ledger/certs.go +113 -0
  158. package/ledger/chainsync.go +578 -0
  159. package/ledger/eras/allegra.go +154 -0
  160. package/ledger/eras/alonzo.go +156 -0
  161. package/ledger/eras/babbage.go +154 -0
  162. package/ledger/eras/byron.go +42 -0
  163. package/ledger/eras/conway.go +158 -0
  164. package/ledger/eras/eras.go +44 -0
  165. package/ledger/eras/mary.go +154 -0
  166. package/ledger/eras/shelley.go +164 -0
  167. package/ledger/error.go +19 -0
  168. package/ledger/event.go +50 -0
  169. package/ledger/metrics.go +53 -0
  170. package/ledger/queries.go +260 -0
  171. package/ledger/slot.go +127 -0
  172. package/ledger/slot_test.go +147 -0
  173. package/ledger/state.go +726 -0
  174. package/ledger/view.go +73 -0
  175. package/localstatequery.go +50 -0
  176. package/localtxmonitor.go +44 -0
  177. package/localtxsubmission.go +52 -0
  178. package/mempool/consumer.go +98 -0
  179. package/mempool/mempool.go +322 -0
  180. package/node.go +320 -0
  181. package/package.json +33 -0
  182. package/peergov/event.go +27 -0
  183. package/peergov/peer.go +67 -0
  184. package/peergov/peergov.go +290 -0
  185. package/peersharing.go +70 -0
  186. package/preview-local-topology.json +23 -0
  187. package/topology/topology.go +69 -0
  188. package/topology/topology_test.go +179 -0
  189. package/tracing.go +65 -0
  190. package/txsubmission.go +233 -0
  191. package/utxorpc/query.go +311 -0
  192. package/utxorpc/submit.go +395 -0
  193. package/utxorpc/sync.go +276 -0
  194. package/utxorpc/utxorpc.go +166 -0
  195. package/utxorpc/watch.go +310 -0
package/node.go ADDED
@@ -0,0 +1,320 @@
1
+ // Copyright 2024 Blink Labs Software
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ package dingo
16
+
17
+ import (
18
+ "context"
19
+ "errors"
20
+ "fmt"
21
+ "slices"
22
+
23
+ "github.com/blinklabs-io/dingo/chainsync"
24
+ "github.com/blinklabs-io/dingo/connmanager"
25
+ "github.com/blinklabs-io/dingo/event"
26
+ "github.com/blinklabs-io/dingo/ledger"
27
+ "github.com/blinklabs-io/dingo/mempool"
28
+ "github.com/blinklabs-io/dingo/peergov"
29
+ "github.com/blinklabs-io/dingo/utxorpc"
30
+ ouroboros "github.com/blinklabs-io/gouroboros"
31
+ oblockfetch "github.com/blinklabs-io/gouroboros/protocol/blockfetch"
32
+ ochainsync "github.com/blinklabs-io/gouroboros/protocol/chainsync"
33
+ olocalstatequery "github.com/blinklabs-io/gouroboros/protocol/localstatequery"
34
+ olocaltxmonitor "github.com/blinklabs-io/gouroboros/protocol/localtxmonitor"
35
+ olocaltxsubmission "github.com/blinklabs-io/gouroboros/protocol/localtxsubmission"
36
+ opeersharing "github.com/blinklabs-io/gouroboros/protocol/peersharing"
37
+ otxsubmission "github.com/blinklabs-io/gouroboros/protocol/txsubmission"
38
+ )
39
+
40
+ type Node struct {
41
+ config Config
42
+ connManager *connmanager.ConnectionManager
43
+ peerGov *peergov.PeerGovernor
44
+ chainsyncState *chainsync.State
45
+ eventBus *event.EventBus
46
+ mempool *mempool.Mempool
47
+ ledgerState *ledger.LedgerState
48
+ utxorpc *utxorpc.Utxorpc
49
+ shutdownFuncs []func(context.Context) error
50
+ }
51
+
52
+ func New(cfg Config) (*Node, error) {
53
+ eventBus := event.NewEventBus(cfg.promRegistry)
54
+ n := &Node{
55
+ config: cfg,
56
+ eventBus: eventBus,
57
+ }
58
+ if err := n.configPopulateNetworkMagic(); err != nil {
59
+ return nil, fmt.Errorf("invalid configuration: %w", err)
60
+ }
61
+ if err := n.configValidate(); err != nil {
62
+ return nil, fmt.Errorf("invalid configuration: %w", err)
63
+ }
64
+ return n, nil
65
+ }
66
+
67
+ func (n *Node) Run() error {
68
+ // Configure tracing
69
+ if n.config.tracing {
70
+ if err := n.setupTracing(); err != nil {
71
+ return err
72
+ }
73
+ }
74
+ // Load state
75
+ state, err := ledger.NewLedgerState(
76
+ ledger.LedgerStateConfig{
77
+ DataDir: n.config.dataDir,
78
+ EventBus: n.eventBus,
79
+ Logger: n.config.logger,
80
+ CardanoNodeConfig: n.config.cardanoNodeConfig,
81
+ PromRegistry: n.config.promRegistry,
82
+ BlockfetchRequestRangeFunc: n.blockfetchClientRequestRange,
83
+ },
84
+ )
85
+ if err != nil {
86
+ return fmt.Errorf("failed to load state database: %w", err)
87
+ }
88
+ // Add shutdown cleanup for ledger/database
89
+ n.shutdownFuncs = append(
90
+ n.shutdownFuncs,
91
+ func(_ context.Context) error {
92
+ return state.Close()
93
+ },
94
+ )
95
+ n.ledgerState = state
96
+ // Initialize mempool
97
+ n.mempool = mempool.NewMempool(
98
+ n.config.logger,
99
+ n.eventBus,
100
+ n.config.promRegistry,
101
+ n.ledgerState,
102
+ )
103
+ // Initialize chainsync state
104
+ n.chainsyncState = chainsync.NewState(
105
+ n.eventBus,
106
+ n.ledgerState,
107
+ )
108
+ // Configure connection manager
109
+ if err := n.configureConnManager(); err != nil {
110
+ return err
111
+ }
112
+ // Configure peer governor
113
+ n.peerGov = peergov.NewPeerGovernor(
114
+ peergov.PeerGovernorConfig{
115
+ Logger: n.config.logger,
116
+ EventBus: n.eventBus,
117
+ ConnManager: n.connManager,
118
+ },
119
+ )
120
+ n.eventBus.SubscribeFunc(
121
+ peergov.OutboundConnectionEventType,
122
+ n.handleOutboundConnEvent,
123
+ )
124
+ if n.config.topologyConfig != nil {
125
+ n.peerGov.LoadTopologyConfig(n.config.topologyConfig)
126
+ }
127
+ if err := n.peerGov.Start(); err != nil {
128
+ return err
129
+ }
130
+ // Configure UTxO RPC
131
+ n.utxorpc = utxorpc.NewUtxorpc(
132
+ utxorpc.UtxorpcConfig{
133
+ Logger: n.config.logger,
134
+ EventBus: n.eventBus,
135
+ LedgerState: n.ledgerState,
136
+ Mempool: n.mempool,
137
+ Port: n.config.utxorpcPort,
138
+ },
139
+ )
140
+ if err := n.utxorpc.Start(); err != nil {
141
+ return err
142
+ }
143
+
144
+ // Wait forever
145
+ select {}
146
+ }
147
+
148
+ func (n *Node) Stop() error {
149
+ return n.shutdown()
150
+ }
151
+
152
+ func (n *Node) shutdown() error {
153
+ ctx := context.TODO()
154
+ var err error
155
+ // Shutdown ledger
156
+ err = errors.Join(err, n.ledgerState.Close())
157
+ // Call shutdown functions
158
+ for _, fn := range n.shutdownFuncs {
159
+ err = errors.Join(err, fn(ctx))
160
+ }
161
+ n.shutdownFuncs = nil
162
+ return err
163
+ }
164
+
165
+ func (n *Node) configureConnManager() error {
166
+ // Configure listeners
167
+ tmpListeners := make([]ListenerConfig, len(n.config.listeners))
168
+ for idx, l := range n.config.listeners {
169
+ if l.UseNtC {
170
+ // Node-to-client
171
+ l.ConnectionOpts = append(
172
+ l.ConnectionOpts,
173
+ ouroboros.WithNetworkMagic(n.config.networkMagic),
174
+ ouroboros.WithChainSyncConfig(
175
+ ochainsync.NewConfig(
176
+ n.chainsyncServerConnOpts()...,
177
+ ),
178
+ ),
179
+ ouroboros.WithLocalStateQueryConfig(
180
+ olocalstatequery.NewConfig(
181
+ n.localstatequeryServerConnOpts()...,
182
+ ),
183
+ ),
184
+ ouroboros.WithLocalTxMonitorConfig(
185
+ olocaltxmonitor.NewConfig(
186
+ n.localtxmonitorServerConnOpts()...,
187
+ ),
188
+ ),
189
+ ouroboros.WithLocalTxSubmissionConfig(
190
+ olocaltxsubmission.NewConfig(
191
+ n.localtxsubmissionServerConnOpts()...,
192
+ ),
193
+ ),
194
+ )
195
+ } else {
196
+ // Node-to-node config
197
+ l.ConnectionOpts = append(
198
+ l.ConnectionOpts,
199
+ ouroboros.WithPeerSharing(n.config.peerSharing),
200
+ ouroboros.WithNetworkMagic(n.config.networkMagic),
201
+ ouroboros.WithPeerSharingConfig(
202
+ opeersharing.NewConfig(
203
+ n.peersharingServerConnOpts()...,
204
+ ),
205
+ ),
206
+ ouroboros.WithTxSubmissionConfig(
207
+ otxsubmission.NewConfig(
208
+ n.txsubmissionServerConnOpts()...,
209
+ ),
210
+ ),
211
+ ouroboros.WithChainSyncConfig(
212
+ ochainsync.NewConfig(
213
+ n.chainsyncServerConnOpts()...,
214
+ ),
215
+ ),
216
+ ouroboros.WithBlockFetchConfig(
217
+ oblockfetch.NewConfig(
218
+ n.blockfetchServerConnOpts()...,
219
+ ),
220
+ ),
221
+ )
222
+ }
223
+ tmpListeners[idx] = l
224
+ }
225
+ // Create connection manager
226
+ n.connManager = connmanager.NewConnectionManager(
227
+ connmanager.ConnectionManagerConfig{
228
+ Logger: n.config.logger,
229
+ EventBus: n.eventBus,
230
+ Listeners: tmpListeners,
231
+ OutboundSourcePort: n.config.outboundSourcePort,
232
+ OutboundConnOpts: []ouroboros.ConnectionOptionFunc{
233
+ ouroboros.WithNetworkMagic(n.config.networkMagic),
234
+ ouroboros.WithNodeToNode(true),
235
+ ouroboros.WithKeepAlive(true),
236
+ ouroboros.WithFullDuplex(true),
237
+ ouroboros.WithPeerSharing(n.config.peerSharing),
238
+ ouroboros.WithPeerSharingConfig(
239
+ opeersharing.NewConfig(
240
+ slices.Concat(
241
+ n.peersharingClientConnOpts(),
242
+ n.peersharingServerConnOpts(),
243
+ )...,
244
+ ),
245
+ ),
246
+ ouroboros.WithTxSubmissionConfig(
247
+ otxsubmission.NewConfig(
248
+ slices.Concat(
249
+ n.txsubmissionClientConnOpts(),
250
+ n.txsubmissionServerConnOpts(),
251
+ )...,
252
+ ),
253
+ ),
254
+ ouroboros.WithChainSyncConfig(
255
+ ochainsync.NewConfig(
256
+ slices.Concat(
257
+ n.chainsyncClientConnOpts(),
258
+ n.chainsyncServerConnOpts(),
259
+ )...,
260
+ ),
261
+ ),
262
+ ouroboros.WithBlockFetchConfig(
263
+ oblockfetch.NewConfig(
264
+ slices.Concat(
265
+ n.blockfetchClientConnOpts(),
266
+ n.blockfetchServerConnOpts(),
267
+ )...,
268
+ ),
269
+ ),
270
+ },
271
+ },
272
+ )
273
+ // Subscribe to connection closed events
274
+ n.eventBus.SubscribeFunc(
275
+ connmanager.ConnectionClosedEventType,
276
+ n.handleConnClosedEvent,
277
+ )
278
+ // Start listeners
279
+ if err := n.connManager.Start(); err != nil {
280
+ return err
281
+ }
282
+ return nil
283
+ }
284
+
285
+ func (n *Node) handleConnClosedEvent(evt event.Event) {
286
+ e := evt.Data.(connmanager.ConnectionClosedEvent)
287
+ connId := e.ConnectionId
288
+ // Remove any chainsync client state
289
+ n.chainsyncState.RemoveClient(connId)
290
+ // Remove mempool consumer
291
+ n.mempool.RemoveConsumer(connId)
292
+ // Release chainsync client
293
+ n.chainsyncState.RemoveClientConnId(connId)
294
+ }
295
+
296
+ func (n *Node) handleOutboundConnEvent(evt event.Event) {
297
+ e := evt.Data.(peergov.OutboundConnectionEvent)
298
+ connId := e.ConnectionId
299
+ // TODO: replace this with handling for multiple chainsync clients (#385)
300
+ // Start chainsync client if we don't have another
301
+ n.chainsyncState.Lock()
302
+ defer n.chainsyncState.Unlock()
303
+ chainsyncClientConnId := n.chainsyncState.GetClientConnId()
304
+ if chainsyncClientConnId == nil {
305
+ if err := n.chainsyncClientStart(connId); err != nil {
306
+ n.config.logger.Error(
307
+ "failed to start chainsync client",
308
+ "error",
309
+ err,
310
+ )
311
+ return
312
+ }
313
+ n.chainsyncState.SetClientConnId(connId)
314
+ }
315
+ // Start txsubmission client
316
+ if err := n.txsubmissionClientStart(connId); err != nil {
317
+ n.config.logger.Error("failed to start chainsync client", "error", err)
318
+ return
319
+ }
320
+ }
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@blinklabs/dingo",
3
+ "version": "0.6.0",
4
+ "description": "Dingo is a Cardano blockchain data node",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "postinstall": "golang-npm install",
8
+ "preuninstall": "golang-npm uninstall",
9
+ "test": "echo \"Error: no test specified\" && exit 1"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/blinklabs-io/dingo.git"
14
+ },
15
+ "keywords": [
16
+ "go",
17
+ "cardano-node"
18
+ ],
19
+ "author": "Blink Labs Software",
20
+ "license": "Apache-2.0",
21
+ "bugs": {
22
+ "url": "https://github.com/blinklabs-io/dingo/issues"
23
+ },
24
+ "homepage": "https://github.com/blinklabs-io/dingo#readme",
25
+ "dependencies": {
26
+ "golang-npm": "^0.0.5"
27
+ },
28
+ "goBinary": {
29
+ "name": "dingo",
30
+ "path": "./bin",
31
+ "url": "https://github.com/blinklabs-io/dingo/releases/download/v{{version}}/dingo-{{version}}-{{platform}}-{{arch}}.tar.gz"
32
+ }
33
+ }
@@ -0,0 +1,27 @@
1
+ // Copyright 2024 Blink Labs Software
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ package peergov
16
+
17
+ import (
18
+ ouroboros "github.com/blinklabs-io/gouroboros"
19
+ )
20
+
21
+ const (
22
+ OutboundConnectionEventType = "peergov.outbound-conn"
23
+ )
24
+
25
+ type OutboundConnectionEvent struct {
26
+ ConnectionId ouroboros.ConnectionId
27
+ }
@@ -0,0 +1,67 @@
1
+ // Copyright 2024 Blink Labs Software
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ package peergov
16
+
17
+ import (
18
+ "time"
19
+
20
+ ouroboros "github.com/blinklabs-io/gouroboros"
21
+ oprotocol "github.com/blinklabs-io/gouroboros/protocol"
22
+ )
23
+
24
+ type PeerSource uint16
25
+
26
+ const (
27
+ PeerSourceUnknown = 0
28
+ PeerSourceTopologyLocalRoot = 1
29
+ PeerSourceTopologyPublicRoot = 2
30
+ PeerSourceTopologyBootstrapPeer = 3
31
+ PeerSourceP2PLedger = 4
32
+ PeerSourceP2PGossip = 5
33
+ PeerSourceInboundConn = 6
34
+ )
35
+
36
+ type Peer struct {
37
+ Address string
38
+ Source PeerSource
39
+ Connection *PeerConnection
40
+ Sharable bool
41
+ ReconnectCount int
42
+ ReconnectDelay time.Duration
43
+ }
44
+
45
+ func (p *Peer) setConnection(conn *ouroboros.Connection, outbound bool) {
46
+ connId := conn.Id()
47
+ protoVersion, versionData := conn.ProtocolVersion()
48
+ p.Connection = &PeerConnection{
49
+ Id: connId,
50
+ ProtocolVersion: uint(protoVersion),
51
+ VersionData: versionData,
52
+ }
53
+ // Determine whether connection can be used as a client
54
+ // This should be true for any outbound connections and any inbound
55
+ // connections in full-duplex mode
56
+ if outbound ||
57
+ versionData.DiffusionMode() == oprotocol.DiffusionModeInitiatorAndResponder {
58
+ p.Connection.IsClient = true
59
+ }
60
+ }
61
+
62
+ type PeerConnection struct {
63
+ Id ouroboros.ConnectionId
64
+ ProtocolVersion uint
65
+ VersionData oprotocol.VersionData
66
+ IsClient bool
67
+ }