@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
@@ -0,0 +1,152 @@
1
+ // Copyright 2025 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 badger
16
+
17
+ import (
18
+ "errors"
19
+ "fmt"
20
+ "io"
21
+ "io/fs"
22
+ "log/slog"
23
+ "os"
24
+ "path/filepath"
25
+ "time"
26
+
27
+ "github.com/blinklabs-io/dingo/database/plugin"
28
+ badger "github.com/dgraph-io/badger/v4"
29
+ )
30
+
31
+ // Register plugin
32
+ func init() {
33
+ plugin.Register(
34
+ plugin.PluginEntry{
35
+ Type: plugin.PluginTypeMetadata,
36
+ Name: "sqlite",
37
+ },
38
+ )
39
+ }
40
+
41
+ // BlobStoreBadger stores all data in badger. Data may not be persisted
42
+ type BlobStoreBadger struct {
43
+ dataDir string
44
+ db *badger.DB
45
+ logger *slog.Logger
46
+ gcEnabled bool
47
+ }
48
+
49
+ // New creates a new database
50
+ func New(
51
+ dataDir string,
52
+ logger *slog.Logger,
53
+ ) (*BlobStoreBadger, error) {
54
+ var blobDb *badger.DB
55
+ var err error
56
+ db := &BlobStoreBadger{
57
+ dataDir: dataDir,
58
+ logger: logger,
59
+ }
60
+ if dataDir == "" {
61
+ // No dataDir, use in-memory config
62
+ badgerOpts := badger.DefaultOptions("").
63
+ WithLogger(NewBadgerLogger(logger)).
64
+ // The default INFO logging is a bit verbose
65
+ WithLoggingLevel(badger.WARNING).
66
+ WithInMemory(true)
67
+ blobDb, err = badger.Open(badgerOpts)
68
+ if err != nil {
69
+ return nil, err
70
+ }
71
+ } else {
72
+ // Make sure that we can read data dir, and create if it doesn't exist
73
+ if _, err := os.Stat(dataDir); err != nil {
74
+ if !errors.Is(err, fs.ErrNotExist) {
75
+ return nil, fmt.Errorf("failed to read data dir: %w", err)
76
+ }
77
+ // Create data directory
78
+ if err := os.MkdirAll(dataDir, fs.ModePerm); err != nil {
79
+ return nil, fmt.Errorf("failed to create data dir: %w", err)
80
+ }
81
+ }
82
+ blobDir := filepath.Join(
83
+ dataDir,
84
+ "blob",
85
+ )
86
+ // Run GC periodically
87
+ db.gcEnabled = true
88
+ badgerOpts := badger.DefaultOptions(blobDir).
89
+ WithLogger(NewBadgerLogger(logger)).
90
+ // The default INFO logging is a bit verbose
91
+ WithLoggingLevel(badger.WARNING)
92
+ blobDb, err = badger.Open(badgerOpts)
93
+ if err != nil {
94
+ return nil, err
95
+ }
96
+ }
97
+ db.db = blobDb
98
+ if err := db.init(); err != nil {
99
+ return db, err
100
+ }
101
+ return db, nil
102
+ }
103
+
104
+ func (d *BlobStoreBadger) init() error {
105
+ if d.logger == nil {
106
+ // Create logger to throw away logs
107
+ // We do this so we don't have to add guards around every log operation
108
+ d.logger = slog.New(slog.NewJSONHandler(io.Discard, nil))
109
+ }
110
+ // Configure metrics
111
+ d.registerBlobMetrics()
112
+ // Configure GC
113
+ if d.gcEnabled {
114
+ go d.blobGc(time.NewTicker(5 * time.Minute))
115
+ }
116
+ return nil
117
+ }
118
+
119
+ func (d *BlobStoreBadger) blobGc(t *time.Ticker) {
120
+ for range t.C {
121
+ again:
122
+ err := d.DB().RunValueLogGC(0.5)
123
+ if err != nil {
124
+ // Log any actual errors
125
+ if !errors.Is(err, badger.ErrNoRewrite) {
126
+ d.logger.Warn(
127
+ fmt.Sprintf("blob DB: GC failure: %s", err),
128
+ "component", "database",
129
+ )
130
+ }
131
+ } else {
132
+ // Run it again if it just ran successfully
133
+ goto again
134
+ }
135
+ }
136
+ }
137
+
138
+ // Close gets the database handle from our BlobStore and closes it
139
+ func (d *BlobStoreBadger) Close() error {
140
+ db := d.DB()
141
+ return db.Close()
142
+ }
143
+
144
+ // DB returns the database handle
145
+ func (d *BlobStoreBadger) DB() *badger.DB {
146
+ return d.db
147
+ }
148
+
149
+ // NewTransaction creates a new badger transaction
150
+ func (d *BlobStoreBadger) NewTransaction(update bool) *badger.Txn {
151
+ return d.DB().NewTransaction(update)
152
+ }
@@ -0,0 +1,63 @@
1
+ // Copyright 2025 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 badger
16
+
17
+ import (
18
+ "fmt"
19
+ "io"
20
+ "log/slog"
21
+ )
22
+
23
+ // BadgerLogger is a wrapper type to give our logger the expected interface
24
+ type BadgerLogger struct {
25
+ logger *slog.Logger
26
+ }
27
+
28
+ func NewBadgerLogger(logger *slog.Logger) *BadgerLogger {
29
+ if logger == nil {
30
+ // Create logger to throw away logs
31
+ // We do this so we don't have to add guards around every log operation
32
+ logger = slog.New(slog.NewJSONHandler(io.Discard, nil))
33
+ }
34
+ return &BadgerLogger{logger: logger}
35
+ }
36
+
37
+ func (b *BadgerLogger) Infof(msg string, args ...any) {
38
+ b.logger.Info(
39
+ fmt.Sprintf(msg, args...),
40
+ "component", "database",
41
+ )
42
+ }
43
+
44
+ func (b *BadgerLogger) Warningf(msg string, args ...any) {
45
+ b.logger.Warn(
46
+ fmt.Sprintf(msg, args...),
47
+ "component", "database",
48
+ )
49
+ }
50
+
51
+ func (b *BadgerLogger) Debugf(msg string, args ...any) {
52
+ b.logger.Debug(
53
+ fmt.Sprintf(msg, args...),
54
+ "component", "database",
55
+ )
56
+ }
57
+
58
+ func (b *BadgerLogger) Errorf(msg string, args ...any) {
59
+ b.logger.Error(
60
+ fmt.Sprintf(msg, args...),
61
+ "component", "database",
62
+ )
63
+ }
@@ -0,0 +1,98 @@
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 badger
16
+
17
+ import (
18
+ "github.com/prometheus/client_golang/prometheus"
19
+ "github.com/prometheus/client_golang/prometheus/collectors"
20
+ )
21
+
22
+ const (
23
+ badgerMetricNamePrefix = "database_blob_"
24
+ )
25
+
26
+ func (d *BlobStoreBadger) registerBlobMetrics() {
27
+ // Badger exposes metrics via expvar, so we need to set up some translation
28
+ collector := collectors.NewExpvarCollector(
29
+ map[string]*prometheus.Desc{
30
+ // This list of metrics is derived from the metrics defined here:
31
+ // https://github.com/dgraph-io/badger/blob/v4.2.0/y/metrics.go#L78-L107
32
+ "badger_read_num_vlog": prometheus.NewDesc(
33
+ badgerMetricNamePrefix+"read_num_vlog", "", nil, nil,
34
+ ),
35
+ "badger_read_bytes_vlog": prometheus.NewDesc(
36
+ badgerMetricNamePrefix+"read_bytes_vlog", "", nil, nil,
37
+ ),
38
+ "badger_write_num_vlog": prometheus.NewDesc(
39
+ badgerMetricNamePrefix+"write_num_vlog", "", nil, nil,
40
+ ),
41
+ "badger_write_bytes_vlog": prometheus.NewDesc(
42
+ badgerMetricNamePrefix+"write_bytes_vlog", "", nil, nil,
43
+ ),
44
+ "badger_read_bytes_lsm": prometheus.NewDesc(
45
+ badgerMetricNamePrefix+"read_bytes_lsm", "", nil, nil,
46
+ ),
47
+ "badger_write_bytes_l0": prometheus.NewDesc(
48
+ badgerMetricNamePrefix+"write_bytes_l0", "", nil, nil,
49
+ ),
50
+ "badger_write_bytes_compaction": prometheus.NewDesc(
51
+ badgerMetricNamePrefix+"write_bytes_compaction", "", nil, nil,
52
+ ),
53
+ "badger_get_num_lsm": prometheus.NewDesc(
54
+ badgerMetricNamePrefix+"get_num_lsm", "", nil, nil,
55
+ ),
56
+ "badger_hit_num_lsm_bloom_filter": prometheus.NewDesc(
57
+ badgerMetricNamePrefix+"hit_num_lsm_bloom_filter", "", nil, nil,
58
+ ),
59
+ "badger_get_num_memtable": prometheus.NewDesc(
60
+ badgerMetricNamePrefix+"get_num_memtable", "", nil, nil,
61
+ ),
62
+ "badger_get_num_user": prometheus.NewDesc(
63
+ badgerMetricNamePrefix+"get_num_user", "", nil, nil,
64
+ ),
65
+ "badger_put_num_user": prometheus.NewDesc(
66
+ badgerMetricNamePrefix+"put_num_user", "", nil, nil,
67
+ ),
68
+ "badger_write_bytes_user": prometheus.NewDesc(
69
+ badgerMetricNamePrefix+"write_bytes_user", "", nil, nil,
70
+ ),
71
+ "badger_get_with_result_num_user": prometheus.NewDesc(
72
+ badgerMetricNamePrefix+"get_with_result_num_user", "", nil, nil,
73
+ ),
74
+ "badger_iterator_num_user": prometheus.NewDesc(
75
+ badgerMetricNamePrefix+"iterator_num_user", "", nil, nil,
76
+ ),
77
+ "badger_size_bytes_lsm": prometheus.NewDesc(
78
+ badgerMetricNamePrefix+"size_bytes_lsm", "", nil, nil,
79
+ ),
80
+ "badger_size_bytes_vlog": prometheus.NewDesc(
81
+ badgerMetricNamePrefix+"size_bytes_vlog", "", nil, nil,
82
+ ),
83
+ "badger_write_pending_num_memtable": prometheus.NewDesc(
84
+ badgerMetricNamePrefix+"write_pending_num_memtable",
85
+ "",
86
+ nil,
87
+ nil,
88
+ ),
89
+ "badger_compaction_current_num_lsm": prometheus.NewDesc(
90
+ badgerMetricNamePrefix+"compaction_current_num_lsm",
91
+ "",
92
+ nil,
93
+ nil,
94
+ ),
95
+ },
96
+ )
97
+ prometheus.MustRegister(collector)
98
+ }
@@ -0,0 +1,19 @@
1
+ // Copyright 2025 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 blob
16
+
17
+ import (
18
+ _ "github.com/blinklabs-io/dingo/database/plugin/blob/badger"
19
+ )
@@ -0,0 +1,40 @@
1
+ // Copyright 2025 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 blob
16
+
17
+ import (
18
+ "log/slog"
19
+
20
+ badgerPlugin "github.com/blinklabs-io/dingo/database/plugin/blob/badger"
21
+ badger "github.com/dgraph-io/badger/v4"
22
+ )
23
+
24
+ type BlobStore interface {
25
+ // matches badger.DB
26
+ Close() error
27
+ NewTransaction(bool) *badger.Txn
28
+
29
+ // Our specific functions
30
+ GetCommitTimestamp() (int64, error)
31
+ SetCommitTimestamp(*badger.Txn, int64) error
32
+ }
33
+
34
+ // For now, this always returns a badger plugin
35
+ func New(
36
+ pluginName, dataDir string,
37
+ logger *slog.Logger,
38
+ ) (BlobStore, error) {
39
+ return badgerPlugin.New(dataDir, logger)
40
+ }
@@ -0,0 +1,27 @@
1
+ // Copyright 2025 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 plugin
16
+
17
+ // Logger provides a logging interface for plugins.
18
+ type Logger interface {
19
+ Info(string, ...any)
20
+ Warn(string, ...any)
21
+ Debug(string, ...any)
22
+ Error(string, ...any)
23
+
24
+ // Deprecated
25
+ // Fatal(string, ...any) in favor of Error
26
+ // With slog Fatal is replaced with Error and os.Exit(1)
27
+ }
@@ -0,0 +1,19 @@
1
+ // Copyright 2025 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 metadata
16
+
17
+ import (
18
+ _ "github.com/blinklabs-io/dingo/database/plugin/metadata/sqlite"
19
+ )
@@ -0,0 +1,224 @@
1
+ // Copyright 2025 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 sqlite
16
+
17
+ import (
18
+ "github.com/blinklabs-io/dingo/database/plugin/metadata/sqlite/models"
19
+ lcommon "github.com/blinklabs-io/gouroboros/ledger/common"
20
+ "gorm.io/gorm"
21
+ "gorm.io/gorm/clause"
22
+ )
23
+
24
+ // GetAccount gets an account
25
+ func (d *MetadataStoreSqlite) GetAccount(
26
+ stakeKey []byte,
27
+ txn *gorm.DB,
28
+ ) (models.Account, error) {
29
+ ret := models.Account{}
30
+ tmpAccount := models.Account{}
31
+ if txn != nil {
32
+ if result := txn.First(&tmpAccount, "staking_key = ?", stakeKey); result.Error != nil {
33
+ return ret, result.Error
34
+ }
35
+ } else {
36
+ if result := d.DB().First(&tmpAccount, "staking_key = ?", stakeKey); result.Error != nil {
37
+ return ret, result.Error
38
+ }
39
+ }
40
+ ret = tmpAccount
41
+ return ret, nil
42
+ }
43
+
44
+ // SetAccount saves an account
45
+ func (d *MetadataStoreSqlite) SetAccount(
46
+ stakeKey, pkh, drep []byte,
47
+ slot uint64,
48
+ active bool,
49
+ txn *gorm.DB,
50
+ ) error {
51
+ tmpItem := models.Account{
52
+ StakingKey: stakeKey,
53
+ AddedSlot: slot,
54
+ Pool: pkh,
55
+ Drep: drep,
56
+ }
57
+ if txn != nil {
58
+ if result := txn.Clauses(clause.OnConflict{UpdateAll: true}).Create(&tmpItem); result.Error != nil {
59
+ return result.Error
60
+ }
61
+ } else {
62
+ if result := d.DB().Clauses(clause.OnConflict{UpdateAll: true}).Create(&tmpItem); result.Error != nil {
63
+ return result.Error
64
+ }
65
+ }
66
+ return nil
67
+ }
68
+
69
+ // SetDeregistration saves a deregistration certificate
70
+ func (d *MetadataStoreSqlite) SetDeregistration(
71
+ cert *lcommon.DeregistrationCertificate,
72
+ slot uint64,
73
+ txn *gorm.DB,
74
+ ) error {
75
+ stakeKey := cert.StakeCredential.Credential.Bytes()
76
+ tmpAccount, err := d.GetAccount(stakeKey, txn)
77
+ if err != nil {
78
+ return err
79
+ }
80
+ tmpItem := models.Deregistration{
81
+ StakingKey: stakeKey,
82
+ AddedSlot: slot,
83
+ }
84
+ tmpAccount.Active = false
85
+ if txn != nil {
86
+ if accountErr := txn.Save(&tmpAccount); accountErr.Error != nil {
87
+ return accountErr.Error
88
+ }
89
+ if result := txn.Create(&tmpItem); result.Error != nil {
90
+ return result.Error
91
+ }
92
+ } else {
93
+ if accountErr := d.DB().Save(&tmpAccount); accountErr.Error != nil {
94
+ return accountErr.Error
95
+ }
96
+ if result := d.DB().Create(&tmpItem); result.Error != nil {
97
+ return result.Error
98
+ }
99
+ }
100
+ return nil
101
+ }
102
+
103
+ // SetStakeRegistration saves a stake registration certificate and account
104
+ func (d *MetadataStoreSqlite) SetStakeRegistration(
105
+ cert *lcommon.StakeRegistrationCertificate,
106
+ slot, deposit uint64,
107
+ txn *gorm.DB,
108
+ ) error {
109
+ stakeKey := cert.StakeRegistration.Credential.Bytes()
110
+ tmpItem := models.StakeRegistration{
111
+ StakingKey: stakeKey,
112
+ AddedSlot: slot,
113
+ DepositAmount: deposit,
114
+ }
115
+ if err := d.SetAccount(stakeKey, nil, nil, slot, true, txn); err != nil {
116
+ return err
117
+ }
118
+ if txn != nil {
119
+ if result := txn.Create(&tmpItem); result.Error != nil {
120
+ return result.Error
121
+ }
122
+ } else {
123
+ if result := d.DB().Create(&tmpItem); result.Error != nil {
124
+ return result.Error
125
+ }
126
+ }
127
+ return nil
128
+ }
129
+
130
+ // SetRegistration saves a registration certificate and account
131
+ func (d *MetadataStoreSqlite) SetRegistration(
132
+ cert *lcommon.RegistrationCertificate,
133
+ slot, deposit uint64,
134
+ txn *gorm.DB,
135
+ ) error {
136
+ stakeKey := cert.StakeCredential.Credential.Bytes()
137
+ tmpItem := models.Registration{
138
+ StakingKey: stakeKey,
139
+ AddedSlot: slot,
140
+ DepositAmount: deposit,
141
+ }
142
+ if err := d.SetAccount(stakeKey, nil, nil, slot, true, txn); err != nil {
143
+ return err
144
+ }
145
+ if txn != nil {
146
+ if result := txn.Create(&tmpItem); result.Error != nil {
147
+ return result.Error
148
+ }
149
+ } else {
150
+ if result := d.DB().Create(&tmpItem); result.Error != nil {
151
+ return result.Error
152
+ }
153
+ }
154
+ return nil
155
+ }
156
+
157
+ // SetStakeDelegation saves a stake delegation certificate
158
+ func (d *MetadataStoreSqlite) SetStakeDelegation(
159
+ cert *lcommon.StakeDelegationCertificate,
160
+ slot uint64,
161
+ txn *gorm.DB,
162
+ ) error {
163
+ stakeKey := cert.StakeCredential.Credential.Bytes()
164
+ tmpAccount, err := d.GetAccount(stakeKey, txn)
165
+ if err != nil {
166
+ return err
167
+ }
168
+ tmpItem := models.StakeDelegation{
169
+ StakingKey: stakeKey,
170
+ PoolKeyHash: cert.PoolKeyHash[:],
171
+ AddedSlot: slot,
172
+ }
173
+ tmpAccount.Pool = tmpItem.PoolKeyHash
174
+ if txn != nil {
175
+ if accountErr := txn.Save(&tmpAccount); accountErr.Error != nil {
176
+ return accountErr.Error
177
+ }
178
+ if result := txn.Create(&tmpItem); result.Error != nil {
179
+ return result.Error
180
+ }
181
+ } else {
182
+ if accountErr := d.DB().Save(&tmpAccount); accountErr.Error != nil {
183
+ return accountErr.Error
184
+ }
185
+ if result := d.DB().Create(&tmpItem); result.Error != nil {
186
+ return result.Error
187
+ }
188
+ }
189
+ return nil
190
+ }
191
+
192
+ // SetStakeDeregistration saves a stake deregistration certificate
193
+ func (d *MetadataStoreSqlite) SetStakeDeregistration(
194
+ cert *lcommon.StakeDeregistrationCertificate,
195
+ slot uint64,
196
+ txn *gorm.DB,
197
+ ) error {
198
+ stakeKey := cert.StakeDeregistration.Credential.Bytes()
199
+ tmpAccount, err := d.GetAccount(stakeKey, txn)
200
+ if err != nil {
201
+ return err
202
+ }
203
+ tmpItem := models.StakeDeregistration{
204
+ StakingKey: stakeKey,
205
+ AddedSlot: slot,
206
+ }
207
+ tmpAccount.Active = false
208
+ if txn != nil {
209
+ if accountErr := txn.Save(&tmpAccount); accountErr.Error != nil {
210
+ return accountErr.Error
211
+ }
212
+ if result := txn.Create(&tmpItem); result.Error != nil {
213
+ return result.Error
214
+ }
215
+ } else {
216
+ if accountErr := d.DB().Save(&tmpAccount); accountErr.Error != nil {
217
+ return accountErr.Error
218
+ }
219
+ if result := d.DB().Create(&tmpItem); result.Error != nil {
220
+ return result.Error
221
+ }
222
+ }
223
+ return nil
224
+ }