@blinklabs/dingo 0.6.0 → 0.8.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.
- package/.dingo/blob/000001.sst +0 -0
- package/.dingo/blob/000001.vlog +0 -0
- package/.dingo/blob/DISCARD +0 -0
- package/.dingo/blob/KEYREGISTRY +2 -0
- package/.dingo/blob/MANIFEST +0 -0
- package/.dingo/metadata.sqlite +0 -0
- package/.github/workflows/golangci-lint.yml +1 -1
- package/.github/workflows/publish.yml +1 -7
- package/README.md +2 -1
- package/{dist/dingo_darwin_amd64_v1/dingo → dingo} +0 -0
- package/dingo.yaml.example +53 -0
- package/package.json +5 -5
- package/Dockerfile +0 -25
- package/Makefile +0 -53
- package/blockfetch.go +0 -144
- package/chain/chain.go +0 -504
- package/chain/chain_test.go +0 -468
- package/chain/errors.go +0 -80
- package/chain/event.go +0 -33
- package/chain/iter.go +0 -64
- package/chainsync/chainsync.go +0 -97
- package/chainsync.go +0 -223
- package/cmd/dingo/load.go +0 -52
- package/cmd/dingo/main.go +0 -118
- package/cmd/dingo/serve.go +0 -49
- package/config/cardano/node.go +0 -192
- package/config/cardano/node_test.go +0 -85
- package/config/cardano/preview/README.md +0 -4
- package/config/cardano/preview/alonzo-genesis.json +0 -196
- package/config/cardano/preview/byron-genesis.json +0 -117
- package/config/cardano/preview/config.json +0 -114
- package/config/cardano/preview/conway-genesis.json +0 -297
- package/config/cardano/preview/shelley-genesis.json +0 -68
- package/config.go +0 -245
- package/connmanager/connection_manager.go +0 -105
- package/connmanager/connection_manager_test.go +0 -185
- package/connmanager/event.go +0 -37
- package/connmanager/listener.go +0 -140
- package/connmanager/outbound.go +0 -93
- package/connmanager/socket.go +0 -55
- package/connmanager/unix.go +0 -78
- package/custom-p2p-topology.json +0 -24
- package/custom-p2p-topology.json.backup +0 -24
- package/custom-p2p-topology.json.mainnet +0 -37
- package/database/account.go +0 -138
- package/database/block.go +0 -362
- package/database/certs.go +0 -53
- package/database/commit_timestamp.go +0 -77
- package/database/database.go +0 -118
- package/database/database_test.go +0 -62
- package/database/drep.go +0 -27
- package/database/epoch.go +0 -121
- package/database/immutable/chunk.go +0 -182
- package/database/immutable/immutable.go +0 -350
- package/database/immutable/immutable_test.go +0 -59
- package/database/immutable/primary.go +0 -106
- package/database/immutable/secondary.go +0 -103
- package/database/immutable/testdata/08893.chunk +0 -0
- package/database/immutable/testdata/08893.primary +0 -0
- package/database/immutable/testdata/08893.secondary +0 -0
- package/database/immutable/testdata/08894.chunk +0 -0
- package/database/immutable/testdata/08894.primary +0 -0
- package/database/immutable/testdata/08894.secondary +0 -0
- package/database/immutable/testdata/README.md +0 -4
- package/database/plugin/blob/badger/commit_timestamp.go +0 -50
- package/database/plugin/blob/badger/database.go +0 -152
- package/database/plugin/blob/badger/logger.go +0 -63
- package/database/plugin/blob/badger/metrics.go +0 -98
- package/database/plugin/blob/blob.go +0 -19
- package/database/plugin/blob/store.go +0 -40
- package/database/plugin/log.go +0 -27
- package/database/plugin/metadata/metadata.go +0 -19
- package/database/plugin/metadata/sqlite/account.go +0 -224
- package/database/plugin/metadata/sqlite/certs.go +0 -58
- package/database/plugin/metadata/sqlite/commit_timestamp.go +0 -68
- package/database/plugin/metadata/sqlite/database.go +0 -218
- package/database/plugin/metadata/sqlite/epoch.go +0 -120
- package/database/plugin/metadata/sqlite/models/account.go +0 -81
- package/database/plugin/metadata/sqlite/models/auth_committee_hot.go +0 -26
- package/database/plugin/metadata/sqlite/models/deregistration_drep.go +0 -26
- package/database/plugin/metadata/sqlite/models/drep.go +0 -27
- package/database/plugin/metadata/sqlite/models/epoch.go +0 -31
- package/database/plugin/metadata/sqlite/models/models.go +0 -45
- package/database/plugin/metadata/sqlite/models/pool.go +0 -97
- package/database/plugin/metadata/sqlite/models/pparam_update.go +0 -27
- package/database/plugin/metadata/sqlite/models/pparams.go +0 -27
- package/database/plugin/metadata/sqlite/models/registration_drep.go +0 -28
- package/database/plugin/metadata/sqlite/models/resign_committee_cold.go +0 -27
- package/database/plugin/metadata/sqlite/models/stake_registration_delegation.go +0 -27
- package/database/plugin/metadata/sqlite/models/stake_vote_delegation.go +0 -27
- package/database/plugin/metadata/sqlite/models/stake_vote_registration_delegation.go +0 -27
- package/database/plugin/metadata/sqlite/models/tip.go +0 -26
- package/database/plugin/metadata/sqlite/models/update_drep.go +0 -27
- package/database/plugin/metadata/sqlite/models/utxo.go +0 -30
- package/database/plugin/metadata/sqlite/models/vote_delegation.go +0 -26
- package/database/plugin/metadata/sqlite/models/vote_registration_delegation.go +0 -26
- package/database/plugin/metadata/sqlite/pool.go +0 -240
- package/database/plugin/metadata/sqlite/pparams.go +0 -110
- package/database/plugin/metadata/sqlite/tip.go +0 -83
- package/database/plugin/metadata/sqlite/utxo.go +0 -292
- package/database/plugin/metadata/store.go +0 -168
- package/database/plugin/option.go +0 -190
- package/database/plugin/plugin.go +0 -20
- package/database/plugin/register.go +0 -118
- package/database/pparams.go +0 -145
- package/database/tip.go +0 -45
- package/database/txn.go +0 -147
- package/database/types/types.go +0 -74
- package/database/types/types_test.go +0 -83
- package/database/utxo.go +0 -263
- package/dist/artifacts.json +0 -1
- package/dist/checksums.txt +0 -22
- package/dist/config.yaml +0 -253
- package/dist/dingo-0.5.0-SNAPSHOT-d9431e4.tar.gz +0 -0
- package/dist/dingo-0.5.0-SNAPSHOT-d9431e4.tar.gz.sbom.json +0 -1
- package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_darwin_arm64.tar.gz +0 -0
- package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_darwin_arm64.tar.gz.sbom.json +0 -1
- package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_darwin_x86_64.tar.gz +0 -0
- package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_darwin_x86_64.tar.gz.sbom.json +0 -1
- package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_amd64.apk +0 -0
- package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_amd64.apk.sbom.json +0 -1
- package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_amd64.deb +0 -0
- package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_amd64.deb.sbom.json +0 -1
- package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_amd64.rpm +0 -0
- package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_amd64.rpm.sbom.json +0 -1
- package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_arm64.apk +0 -0
- package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_arm64.apk.sbom.json +0 -1
- package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_arm64.deb +0 -0
- package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_arm64.deb.sbom.json +0 -1
- package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_arm64.rpm +0 -0
- package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_arm64.rpm.sbom.json +0 -1
- package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_arm64.tar.gz +0 -0
- package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_arm64.tar.gz.sbom.json +0 -1
- package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_x86_64.tar.gz +0 -0
- package/dist/dingo_0.5.0-SNAPSHOT-d9431e4_linux_x86_64.tar.gz.sbom.json +0 -1
- package/dist/dingo_darwin_arm64_v8.0/dingo +0 -0
- package/dist/dingo_linux_amd64_v1/dingo +0 -0
- package/dist/dingo_linux_arm64_v8.0/dingo +0 -0
- package/dist/homebrew/dingo.rb +0 -51
- package/dist/metadata.json +0 -1
- package/event/event.go +0 -141
- package/event/event_test.go +0 -115
- package/event/metrics.go +0 -44
- package/go.mod +0 -98
- package/go.sum +0 -358
- package/internal/config/config.go +0 -145
- package/internal/config/config_test.go +0 -118
- package/internal/node/load.go +0 -149
- package/internal/node/node.go +0 -176
- package/internal/version/version.go +0 -33
- package/ledger/certs.go +0 -113
- package/ledger/chainsync.go +0 -578
- package/ledger/eras/allegra.go +0 -154
- package/ledger/eras/alonzo.go +0 -156
- package/ledger/eras/babbage.go +0 -154
- package/ledger/eras/byron.go +0 -42
- package/ledger/eras/conway.go +0 -158
- package/ledger/eras/eras.go +0 -44
- package/ledger/eras/mary.go +0 -154
- package/ledger/eras/shelley.go +0 -164
- package/ledger/error.go +0 -19
- package/ledger/event.go +0 -50
- package/ledger/metrics.go +0 -53
- package/ledger/queries.go +0 -260
- package/ledger/slot.go +0 -127
- package/ledger/slot_test.go +0 -147
- package/ledger/state.go +0 -726
- package/ledger/view.go +0 -73
- package/localstatequery.go +0 -50
- package/localtxmonitor.go +0 -44
- package/localtxsubmission.go +0 -52
- package/mempool/consumer.go +0 -98
- package/mempool/mempool.go +0 -322
- package/node.go +0 -320
- package/peergov/event.go +0 -27
- package/peergov/peer.go +0 -67
- package/peergov/peergov.go +0 -290
- package/peersharing.go +0 -70
- package/preview-local-topology.json +0 -23
- package/topology/topology.go +0 -69
- package/topology/topology_test.go +0 -179
- package/tracing.go +0 -65
- package/txsubmission.go +0 -233
- package/utxorpc/query.go +0 -311
- package/utxorpc/submit.go +0 -395
- package/utxorpc/sync.go +0 -276
- package/utxorpc/utxorpc.go +0 -166
- package/utxorpc/watch.go +0 -310
package/chain/chain_test.go
DELETED
|
@@ -1,468 +0,0 @@
|
|
|
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 chain_test
|
|
16
|
-
|
|
17
|
-
import (
|
|
18
|
-
"encoding/hex"
|
|
19
|
-
"errors"
|
|
20
|
-
"testing"
|
|
21
|
-
|
|
22
|
-
"github.com/blinklabs-io/dingo/chain"
|
|
23
|
-
"github.com/blinklabs-io/gouroboros/ledger"
|
|
24
|
-
"github.com/blinklabs-io/gouroboros/ledger/common"
|
|
25
|
-
ocommon "github.com/blinklabs-io/gouroboros/protocol/common"
|
|
26
|
-
)
|
|
27
|
-
|
|
28
|
-
type MockBlock struct {
|
|
29
|
-
ledger.ConwayBlock
|
|
30
|
-
MockHash string
|
|
31
|
-
MockSlot uint64
|
|
32
|
-
MockBlockNumber uint64
|
|
33
|
-
MockPrevHash string
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
func (b *MockBlock) Hash() common.Blake2b256 {
|
|
37
|
-
hashBytes, err := hex.DecodeString(b.MockHash)
|
|
38
|
-
if err != nil {
|
|
39
|
-
panic("failed decoding hex: " + err.Error())
|
|
40
|
-
}
|
|
41
|
-
return common.NewBlake2b256(hashBytes)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
func (b *MockBlock) PrevHash() common.Blake2b256 {
|
|
45
|
-
prevHashBytes, err := hex.DecodeString(b.MockPrevHash)
|
|
46
|
-
if err != nil {
|
|
47
|
-
panic("failed decoding hex: " + err.Error())
|
|
48
|
-
}
|
|
49
|
-
return common.NewBlake2b256(prevHashBytes)
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
func (b *MockBlock) SlotNumber() uint64 {
|
|
53
|
-
return b.MockSlot
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
func (b *MockBlock) BlockNumber() uint64 {
|
|
57
|
-
return b.MockBlockNumber
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
var (
|
|
61
|
-
// Mock hash prefix used when building mock hashes in test blocks below
|
|
62
|
-
testHashPrefix = "000047442c8830c700ecb099064ee1b038ed6fd254133f582e906a4bc3fd"
|
|
63
|
-
// Mock nonce value
|
|
64
|
-
testNonce = []byte{0xab, 0xcd, 0xef, 0x01}
|
|
65
|
-
// Mock blocks
|
|
66
|
-
testBlocks = []*MockBlock{
|
|
67
|
-
{
|
|
68
|
-
MockBlockNumber: 1,
|
|
69
|
-
MockSlot: 0,
|
|
70
|
-
MockHash: testHashPrefix + "0001",
|
|
71
|
-
},
|
|
72
|
-
{
|
|
73
|
-
MockBlockNumber: 2,
|
|
74
|
-
MockSlot: 20,
|
|
75
|
-
MockHash: testHashPrefix + "0002",
|
|
76
|
-
MockPrevHash: testHashPrefix + "0001",
|
|
77
|
-
},
|
|
78
|
-
{
|
|
79
|
-
MockBlockNumber: 3,
|
|
80
|
-
MockSlot: 40,
|
|
81
|
-
MockHash: testHashPrefix + "0003",
|
|
82
|
-
MockPrevHash: testHashPrefix + "0002",
|
|
83
|
-
},
|
|
84
|
-
{
|
|
85
|
-
MockBlockNumber: 4,
|
|
86
|
-
MockSlot: 60,
|
|
87
|
-
MockHash: testHashPrefix + "0004",
|
|
88
|
-
MockPrevHash: testHashPrefix + "0003",
|
|
89
|
-
},
|
|
90
|
-
{
|
|
91
|
-
MockBlockNumber: 5,
|
|
92
|
-
MockSlot: 80,
|
|
93
|
-
MockHash: testHashPrefix + "0005",
|
|
94
|
-
MockPrevHash: testHashPrefix + "0004",
|
|
95
|
-
},
|
|
96
|
-
{
|
|
97
|
-
MockBlockNumber: 6,
|
|
98
|
-
MockSlot: 100,
|
|
99
|
-
MockHash: testHashPrefix + "0006",
|
|
100
|
-
MockPrevHash: testHashPrefix + "0005",
|
|
101
|
-
},
|
|
102
|
-
}
|
|
103
|
-
)
|
|
104
|
-
|
|
105
|
-
func TestChainBasic(t *testing.T) {
|
|
106
|
-
c, err := chain.NewChain(
|
|
107
|
-
nil, // db
|
|
108
|
-
nil, // eventBus,
|
|
109
|
-
false, // persistent
|
|
110
|
-
)
|
|
111
|
-
if err != nil {
|
|
112
|
-
t.Fatalf("unexpected error creating chain: %s", err)
|
|
113
|
-
}
|
|
114
|
-
for _, testBlock := range testBlocks {
|
|
115
|
-
if err := c.AddBlock(testBlock, testNonce, nil); err != nil {
|
|
116
|
-
t.Fatalf("unexpected error adding block to chain: %s", err)
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
iter, err := c.FromPoint(ocommon.NewPointOrigin(), false)
|
|
120
|
-
if err != nil {
|
|
121
|
-
t.Fatalf("unexpected error creating chain iterator: %s", err)
|
|
122
|
-
}
|
|
123
|
-
// Iterate until hitting chain tip, and make sure we get blocks in the correct order with
|
|
124
|
-
// all expected data
|
|
125
|
-
testBlockIdx := 0
|
|
126
|
-
for {
|
|
127
|
-
next, err := iter.Next(false)
|
|
128
|
-
if err != nil {
|
|
129
|
-
if errors.Is(err, chain.ErrIteratorChainTip) {
|
|
130
|
-
if testBlockIdx < len(testBlocks)-1 {
|
|
131
|
-
t.Fatal("encountered chain tip before we expected to")
|
|
132
|
-
}
|
|
133
|
-
break
|
|
134
|
-
}
|
|
135
|
-
t.Fatalf(
|
|
136
|
-
"unexpected error getting next block from chain iterator: %s",
|
|
137
|
-
err,
|
|
138
|
-
)
|
|
139
|
-
}
|
|
140
|
-
if testBlockIdx >= len(testBlocks) {
|
|
141
|
-
t.Fatal("ran out of test blocks before reaching chain tip")
|
|
142
|
-
}
|
|
143
|
-
testBlock := testBlocks[testBlockIdx]
|
|
144
|
-
if next.Rollback {
|
|
145
|
-
t.Fatalf("unexpected rollback from chain iterator")
|
|
146
|
-
}
|
|
147
|
-
nextBlock := next.Block
|
|
148
|
-
if nextBlock.ID != uint64(testBlockIdx+1) {
|
|
149
|
-
t.Fatalf(
|
|
150
|
-
"did not get expected block from iterator: got index %d, expected %d",
|
|
151
|
-
nextBlock.ID,
|
|
152
|
-
testBlockIdx+1,
|
|
153
|
-
)
|
|
154
|
-
}
|
|
155
|
-
nextHashHex := hex.EncodeToString(nextBlock.Hash)
|
|
156
|
-
if nextHashHex != testBlock.MockHash {
|
|
157
|
-
t.Fatalf(
|
|
158
|
-
"did not get expected block from iterator: got hash %s, expected %s",
|
|
159
|
-
nextHashHex,
|
|
160
|
-
testBlock.MockHash,
|
|
161
|
-
)
|
|
162
|
-
}
|
|
163
|
-
if testBlock.MockPrevHash != "" {
|
|
164
|
-
nextPrevHashHex := hex.EncodeToString(nextBlock.PrevHash)
|
|
165
|
-
if nextPrevHashHex != testBlock.MockPrevHash {
|
|
166
|
-
t.Fatalf(
|
|
167
|
-
"did not get expected block from iterator: got prev hash %s, expected %s",
|
|
168
|
-
nextPrevHashHex,
|
|
169
|
-
testBlock.MockPrevHash,
|
|
170
|
-
)
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
if nextBlock.Slot != testBlock.MockSlot {
|
|
174
|
-
t.Fatalf(
|
|
175
|
-
"did not get expected block from iterator: got slot %d, expected %d",
|
|
176
|
-
nextBlock.Slot,
|
|
177
|
-
testBlock.MockSlot,
|
|
178
|
-
)
|
|
179
|
-
}
|
|
180
|
-
if nextBlock.Number != testBlock.MockBlockNumber {
|
|
181
|
-
t.Fatalf(
|
|
182
|
-
"did not get expected block from iterator: got block number %d, expected %d",
|
|
183
|
-
nextBlock.Number,
|
|
184
|
-
testBlock.MockBlockNumber,
|
|
185
|
-
)
|
|
186
|
-
}
|
|
187
|
-
nextPoint := next.Point
|
|
188
|
-
if nextPoint.Slot != nextBlock.Slot {
|
|
189
|
-
t.Fatalf(
|
|
190
|
-
"did not get expected point from iterator: got slot %d, expected %d",
|
|
191
|
-
nextPoint.Slot,
|
|
192
|
-
nextBlock.Slot,
|
|
193
|
-
)
|
|
194
|
-
}
|
|
195
|
-
if string(nextPoint.Hash) != string(nextBlock.Hash) {
|
|
196
|
-
t.Fatalf(
|
|
197
|
-
"did not get expected point from iterator: got hash %x, expected %x",
|
|
198
|
-
nextPoint.Hash,
|
|
199
|
-
nextBlock.Hash,
|
|
200
|
-
)
|
|
201
|
-
}
|
|
202
|
-
testBlockIdx++
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
func TestChainRollback(t *testing.T) {
|
|
207
|
-
c, err := chain.NewChain(
|
|
208
|
-
nil, // db
|
|
209
|
-
nil, // eventBus,
|
|
210
|
-
false, // persistent
|
|
211
|
-
)
|
|
212
|
-
if err != nil {
|
|
213
|
-
t.Fatalf("unexpected error creating chain: %s", err)
|
|
214
|
-
}
|
|
215
|
-
for _, testBlock := range testBlocks {
|
|
216
|
-
if err := c.AddBlock(testBlock, testNonce, nil); err != nil {
|
|
217
|
-
t.Fatalf("unexpected error adding block to chain: %s", err)
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
iter, err := c.FromPoint(ocommon.NewPointOrigin(), false)
|
|
221
|
-
if err != nil {
|
|
222
|
-
t.Fatalf("unexpected error creating chain iterator: %s", err)
|
|
223
|
-
}
|
|
224
|
-
// Iterate until hitting chain tip, and make sure we get blocks in the correct order
|
|
225
|
-
testBlockIdx := 0
|
|
226
|
-
for {
|
|
227
|
-
next, err := iter.Next(false)
|
|
228
|
-
if err != nil {
|
|
229
|
-
if errors.Is(err, chain.ErrIteratorChainTip) {
|
|
230
|
-
if testBlockIdx < len(testBlocks)-1 {
|
|
231
|
-
t.Fatal("encountered chain tip before we expected to")
|
|
232
|
-
}
|
|
233
|
-
break
|
|
234
|
-
}
|
|
235
|
-
t.Fatalf(
|
|
236
|
-
"unexpected error getting next block from chain iterator: %s",
|
|
237
|
-
err,
|
|
238
|
-
)
|
|
239
|
-
}
|
|
240
|
-
if testBlockIdx >= len(testBlocks) {
|
|
241
|
-
t.Fatal("ran out of test blocks before reaching chain tip")
|
|
242
|
-
}
|
|
243
|
-
testBlock := testBlocks[testBlockIdx]
|
|
244
|
-
if next.Rollback {
|
|
245
|
-
t.Fatalf("unexpected rollback from chain iterator")
|
|
246
|
-
}
|
|
247
|
-
nextBlock := next.Block
|
|
248
|
-
nextHashHex := hex.EncodeToString(nextBlock.Hash)
|
|
249
|
-
if nextHashHex != testBlock.MockHash {
|
|
250
|
-
t.Fatalf(
|
|
251
|
-
"did not get expected block from iterator: got hash %s, expected %s",
|
|
252
|
-
nextHashHex,
|
|
253
|
-
testBlock.MockHash,
|
|
254
|
-
)
|
|
255
|
-
}
|
|
256
|
-
testBlockIdx++
|
|
257
|
-
}
|
|
258
|
-
// Rollback to specific test block point
|
|
259
|
-
testRollbackIdx := 2
|
|
260
|
-
testRollbackBlock := testBlocks[testRollbackIdx]
|
|
261
|
-
testRollbackPoint := ocommon.Point{
|
|
262
|
-
Slot: testRollbackBlock.SlotNumber(),
|
|
263
|
-
Hash: testRollbackBlock.Hash().Bytes(),
|
|
264
|
-
}
|
|
265
|
-
if err := c.Rollback(testRollbackPoint); err != nil {
|
|
266
|
-
t.Fatalf("unexpected error while rolling back chain: %s", err)
|
|
267
|
-
}
|
|
268
|
-
// Compare chain iterator tip to test rollback point
|
|
269
|
-
chainTip := c.Tip()
|
|
270
|
-
if chainTip.Point.Slot != testRollbackPoint.Slot ||
|
|
271
|
-
string(chainTip.Point.Hash) != string(testRollbackPoint.Hash) {
|
|
272
|
-
t.Fatalf(
|
|
273
|
-
"chain tip does not match expected point after rollback: got %d.%x, wanted %d.%x",
|
|
274
|
-
chainTip.Point.Slot,
|
|
275
|
-
chainTip.Point.Hash,
|
|
276
|
-
testRollbackPoint.Slot,
|
|
277
|
-
testRollbackPoint.Hash,
|
|
278
|
-
)
|
|
279
|
-
}
|
|
280
|
-
// The chain iterator should give us a rollback
|
|
281
|
-
next, err := iter.Next(false)
|
|
282
|
-
if err != nil {
|
|
283
|
-
t.Fatalf("unexpected error calling chain iterator next: %s", err)
|
|
284
|
-
}
|
|
285
|
-
if !next.Rollback {
|
|
286
|
-
t.Fatalf(
|
|
287
|
-
"did not get expected rollback from chain iterator: got %#v",
|
|
288
|
-
next,
|
|
289
|
-
)
|
|
290
|
-
}
|
|
291
|
-
if next.Point.Slot != testRollbackPoint.Slot ||
|
|
292
|
-
string(next.Point.Hash) != string(testRollbackPoint.Hash) {
|
|
293
|
-
t.Fatalf(
|
|
294
|
-
"chain iterator rollback does not match expected point after rollback: got %d.%x, wanted %d.%x",
|
|
295
|
-
next.Point.Slot,
|
|
296
|
-
next.Point.Hash,
|
|
297
|
-
testRollbackPoint.Slot,
|
|
298
|
-
testRollbackPoint.Hash,
|
|
299
|
-
)
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
func TestChainHeaderRange(t *testing.T) {
|
|
304
|
-
testBlockCount := 3
|
|
305
|
-
c, err := chain.NewChain(
|
|
306
|
-
nil, // db
|
|
307
|
-
nil, // eventBus,
|
|
308
|
-
false, // persistent
|
|
309
|
-
)
|
|
310
|
-
if err != nil {
|
|
311
|
-
t.Fatalf("unexpected error creating chain: %s", err)
|
|
312
|
-
}
|
|
313
|
-
// Add blocks
|
|
314
|
-
for _, testBlock := range testBlocks[0:testBlockCount] {
|
|
315
|
-
if err := c.AddBlock(testBlock, testNonce, nil); err != nil {
|
|
316
|
-
t.Fatalf("unexpected error adding block to chain: %s", err)
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
// Add headers
|
|
320
|
-
for _, testBlock := range testBlocks[testBlockCount:] {
|
|
321
|
-
if err := c.AddBlockHeader(testBlock); err != nil {
|
|
322
|
-
t.Fatalf("unexpected error adding header to chain: %s", err)
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
// Compare header range
|
|
326
|
-
start, end := c.HeaderRange(1000)
|
|
327
|
-
testStartBlock := testBlocks[testBlockCount]
|
|
328
|
-
if start.Slot != testStartBlock.SlotNumber() ||
|
|
329
|
-
string(start.Hash) != string(testStartBlock.Hash().Bytes()) {
|
|
330
|
-
t.Fatalf(
|
|
331
|
-
"did not get expected start point: got %d.%x, wanted %d.%s",
|
|
332
|
-
start.Slot,
|
|
333
|
-
start.Hash,
|
|
334
|
-
testStartBlock.SlotNumber(),
|
|
335
|
-
testStartBlock.Hash().String(),
|
|
336
|
-
)
|
|
337
|
-
}
|
|
338
|
-
testEndBlock := testBlocks[len(testBlocks)-1]
|
|
339
|
-
if end.Slot != testEndBlock.SlotNumber() ||
|
|
340
|
-
string(end.Hash) != string(testEndBlock.Hash().Bytes()) {
|
|
341
|
-
t.Fatalf(
|
|
342
|
-
"did not get expected end point: got %d.%x, wanted %d.%s",
|
|
343
|
-
end.Slot,
|
|
344
|
-
end.Hash,
|
|
345
|
-
testEndBlock.SlotNumber(),
|
|
346
|
-
testEndBlock.Hash().String(),
|
|
347
|
-
)
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
func TestChainHeaderBlock(t *testing.T) {
|
|
352
|
-
testBlockCount := 3
|
|
353
|
-
c, err := chain.NewChain(
|
|
354
|
-
nil, // db
|
|
355
|
-
nil, // eventBus,
|
|
356
|
-
false, // persistent
|
|
357
|
-
)
|
|
358
|
-
if err != nil {
|
|
359
|
-
t.Fatalf("unexpected error creating chain: %s", err)
|
|
360
|
-
}
|
|
361
|
-
// Add blocks
|
|
362
|
-
for _, testBlock := range testBlocks[0:testBlockCount] {
|
|
363
|
-
if err := c.AddBlock(testBlock, testNonce, nil); err != nil {
|
|
364
|
-
t.Fatalf("unexpected error adding block to chain: %s", err)
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
// Add headers
|
|
368
|
-
for _, testBlock := range testBlocks[testBlockCount:] {
|
|
369
|
-
if err := c.AddBlockHeader(testBlock); err != nil {
|
|
370
|
-
t.Fatalf("unexpected error adding header to chain: %s", err)
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
// Add blocks for headers
|
|
374
|
-
for _, testBlock := range testBlocks[testBlockCount:] {
|
|
375
|
-
if err := c.AddBlock(testBlock, testNonce, nil); err != nil {
|
|
376
|
-
t.Fatalf("unexpected error adding header to chain: %s", err)
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
func TestChainHeaderWrongBlock(t *testing.T) {
|
|
382
|
-
testBlockCount := 3
|
|
383
|
-
c, err := chain.NewChain(
|
|
384
|
-
nil, // db
|
|
385
|
-
nil, // eventBus,
|
|
386
|
-
false, // persistent
|
|
387
|
-
)
|
|
388
|
-
if err != nil {
|
|
389
|
-
t.Fatalf("unexpected error creating chain: %s", err)
|
|
390
|
-
}
|
|
391
|
-
// Add blocks
|
|
392
|
-
for _, testBlock := range testBlocks[0:testBlockCount] {
|
|
393
|
-
if err := c.AddBlock(testBlock, testNonce, nil); err != nil {
|
|
394
|
-
t.Fatalf("unexpected error adding block to chain: %s", err)
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
// Add headers
|
|
398
|
-
for _, testBlock := range testBlocks[testBlockCount:] {
|
|
399
|
-
if err := c.AddBlockHeader(testBlock); err != nil {
|
|
400
|
-
t.Fatalf("unexpected error adding header to chain: %s", err)
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
// Add wrong next blocks for headers
|
|
404
|
-
testFirstHeader := testBlocks[testBlockCount]
|
|
405
|
-
testWrongBlock := testBlocks[testBlockCount-1]
|
|
406
|
-
testExpectedErr := chain.NewBlockNotMatchHeaderError(
|
|
407
|
-
testWrongBlock.Hash().String(),
|
|
408
|
-
testFirstHeader.Hash().String(),
|
|
409
|
-
)
|
|
410
|
-
err = c.AddBlock(testWrongBlock, testNonce, nil)
|
|
411
|
-
if err == nil {
|
|
412
|
-
t.Fatalf(
|
|
413
|
-
"AddBlock should fail when adding block that doesn't match first header",
|
|
414
|
-
)
|
|
415
|
-
}
|
|
416
|
-
if !errors.Is(err, testExpectedErr) {
|
|
417
|
-
t.Fatalf(
|
|
418
|
-
"did not get expected error: got %#v but wanted %#v",
|
|
419
|
-
err,
|
|
420
|
-
testExpectedErr,
|
|
421
|
-
)
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
func TestChainHeaderRollback(t *testing.T) {
|
|
426
|
-
testBlockCount := 3
|
|
427
|
-
c, err := chain.NewChain(
|
|
428
|
-
nil, // db
|
|
429
|
-
nil, // eventBus,
|
|
430
|
-
false, // persistent
|
|
431
|
-
)
|
|
432
|
-
if err != nil {
|
|
433
|
-
t.Fatalf("unexpected error creating chain: %s", err)
|
|
434
|
-
}
|
|
435
|
-
// Add blocks
|
|
436
|
-
for _, testBlock := range testBlocks[0:testBlockCount] {
|
|
437
|
-
if err := c.AddBlock(testBlock, testNonce, nil); err != nil {
|
|
438
|
-
t.Fatalf("unexpected error adding block to chain: %s", err)
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
// Add headers
|
|
442
|
-
for _, testBlock := range testBlocks[testBlockCount:] {
|
|
443
|
-
if err := c.AddBlockHeader(testBlock); err != nil {
|
|
444
|
-
t.Fatalf("unexpected error adding header to chain: %s", err)
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
// Rollback to first header point
|
|
448
|
-
testFirstHeader := testBlocks[testBlockCount]
|
|
449
|
-
testFirstHeaderPoint := ocommon.Point{
|
|
450
|
-
Slot: testFirstHeader.SlotNumber(),
|
|
451
|
-
Hash: testFirstHeader.Hash().Bytes(),
|
|
452
|
-
}
|
|
453
|
-
if err := c.Rollback(testFirstHeaderPoint); err != nil {
|
|
454
|
-
t.Fatalf("unexpected error doing chain rollback: %s", err)
|
|
455
|
-
}
|
|
456
|
-
// Check header tip matches rollback point
|
|
457
|
-
headerTip := c.HeaderTip()
|
|
458
|
-
if headerTip.Point.Slot != testFirstHeaderPoint.Slot ||
|
|
459
|
-
string(headerTip.Point.Hash) != string(testFirstHeaderPoint.Hash) {
|
|
460
|
-
t.Fatalf(
|
|
461
|
-
"did not get expected chain header tip after rollback: got %d.%x, wanted %d.%x",
|
|
462
|
-
headerTip.Point.Slot,
|
|
463
|
-
headerTip.Point.Hash,
|
|
464
|
-
testFirstHeaderPoint.Slot,
|
|
465
|
-
testFirstHeaderPoint.Hash,
|
|
466
|
-
)
|
|
467
|
-
}
|
|
468
|
-
}
|
package/chain/errors.go
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
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 chain
|
|
16
|
-
|
|
17
|
-
import (
|
|
18
|
-
"errors"
|
|
19
|
-
"fmt"
|
|
20
|
-
)
|
|
21
|
-
|
|
22
|
-
var (
|
|
23
|
-
ErrBlockNotFound = errors.New("block not found")
|
|
24
|
-
ErrRollbackBeyondEphemeralChain = errors.New(
|
|
25
|
-
"cannot rollback ephemeral chain beyond memory buffer",
|
|
26
|
-
)
|
|
27
|
-
ErrIteratorChainTip = errors.New(
|
|
28
|
-
"chain iterator is at chain tip",
|
|
29
|
-
)
|
|
30
|
-
)
|
|
31
|
-
|
|
32
|
-
type BlockNotFitChainTipError struct {
|
|
33
|
-
blockHash string
|
|
34
|
-
blockPrevHash string
|
|
35
|
-
tipHash string
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
func NewBlockNotFitChainTipError(
|
|
39
|
-
blockHash string,
|
|
40
|
-
blockPrevHash string,
|
|
41
|
-
tipHash string,
|
|
42
|
-
) BlockNotFitChainTipError {
|
|
43
|
-
return BlockNotFitChainTipError{
|
|
44
|
-
blockHash: blockHash,
|
|
45
|
-
blockPrevHash: blockPrevHash,
|
|
46
|
-
tipHash: tipHash,
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
func (e BlockNotFitChainTipError) Error() string {
|
|
51
|
-
return fmt.Sprintf(
|
|
52
|
-
"block %s with prev hash %s does not fit on current chain tip %s",
|
|
53
|
-
e.blockHash,
|
|
54
|
-
e.blockPrevHash,
|
|
55
|
-
e.tipHash,
|
|
56
|
-
)
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
type BlockNotMatchHeaderError struct {
|
|
60
|
-
blockHash string
|
|
61
|
-
headerHash string
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
func NewBlockNotMatchHeaderError(
|
|
65
|
-
blockHash string,
|
|
66
|
-
headerHash string,
|
|
67
|
-
) BlockNotMatchHeaderError {
|
|
68
|
-
return BlockNotMatchHeaderError{
|
|
69
|
-
blockHash: blockHash,
|
|
70
|
-
headerHash: headerHash,
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
func (e BlockNotMatchHeaderError) Error() string {
|
|
75
|
-
return fmt.Sprintf(
|
|
76
|
-
"block hash %s does not match first pending header hash %s",
|
|
77
|
-
e.blockHash,
|
|
78
|
-
e.headerHash,
|
|
79
|
-
)
|
|
80
|
-
}
|
package/chain/event.go
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
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 chain
|
|
16
|
-
|
|
17
|
-
import (
|
|
18
|
-
"github.com/blinklabs-io/dingo/database"
|
|
19
|
-
ocommon "github.com/blinklabs-io/gouroboros/protocol/common"
|
|
20
|
-
)
|
|
21
|
-
|
|
22
|
-
const (
|
|
23
|
-
ChainUpdateEventType = "chain.update"
|
|
24
|
-
)
|
|
25
|
-
|
|
26
|
-
type ChainBlockEvent struct {
|
|
27
|
-
Point ocommon.Point
|
|
28
|
-
Block database.Block
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
type ChainRollbackEvent struct {
|
|
32
|
-
Point ocommon.Point
|
|
33
|
-
}
|
package/chain/iter.go
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
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 chain
|
|
16
|
-
|
|
17
|
-
import (
|
|
18
|
-
"github.com/blinklabs-io/dingo/database"
|
|
19
|
-
ocommon "github.com/blinklabs-io/gouroboros/protocol/common"
|
|
20
|
-
)
|
|
21
|
-
|
|
22
|
-
type ChainIterator struct {
|
|
23
|
-
chain *Chain
|
|
24
|
-
startPoint ocommon.Point
|
|
25
|
-
nextBlockIndex uint64
|
|
26
|
-
lastPoint ocommon.Point
|
|
27
|
-
needsRollback bool
|
|
28
|
-
rollbackPoint ocommon.Point
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
type ChainIteratorResult struct {
|
|
32
|
-
Point ocommon.Point
|
|
33
|
-
Block database.Block
|
|
34
|
-
Rollback bool
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
func newChainIterator(
|
|
38
|
-
chain *Chain,
|
|
39
|
-
startPoint ocommon.Point,
|
|
40
|
-
inclusive bool,
|
|
41
|
-
) (*ChainIterator, error) {
|
|
42
|
-
ci := &ChainIterator{
|
|
43
|
-
chain: chain,
|
|
44
|
-
startPoint: startPoint,
|
|
45
|
-
nextBlockIndex: initialBlockIndex,
|
|
46
|
-
}
|
|
47
|
-
// Lookup start block in metadata DB if not origin
|
|
48
|
-
if startPoint.Slot > 0 || len(startPoint.Hash) > 0 {
|
|
49
|
-
tmpBlock, err := chain.BlockByPoint(startPoint, nil)
|
|
50
|
-
if err != nil {
|
|
51
|
-
return nil, err
|
|
52
|
-
}
|
|
53
|
-
ci.nextBlockIndex = tmpBlock.ID
|
|
54
|
-
// Increment next block number if non-inclusive
|
|
55
|
-
if !inclusive {
|
|
56
|
-
ci.nextBlockIndex++
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return ci, nil
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
func (ci *ChainIterator) Next(blocking bool) (*ChainIteratorResult, error) {
|
|
63
|
-
return ci.chain.iterNext(ci, blocking)
|
|
64
|
-
}
|