@blinklabs/dingo 0.7.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/{bin/dingo → dingo} +0 -0
- package/dingo.yaml.example +53 -0
- package/package.json +2 -2
- 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 -180
- 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 -47
- 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 -313
- 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/drep.go +0 -140
- package/database/plugin/metadata/sqlite/epoch.go +0 -120
- package/database/plugin/metadata/sqlite/models/account.go +0 -118
- package/database/plugin/metadata/sqlite/models/auth_committee_hot.go +0 -26
- package/database/plugin/metadata/sqlite/models/drep.go +0 -52
- package/database/plugin/metadata/sqlite/models/epoch.go +0 -31
- package/database/plugin/metadata/sqlite/models/models.go +0 -46
- 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/resign_committee_cold.go +0 -27
- package/database/plugin/metadata/sqlite/models/stake_vote_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 -15
- 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 -198
- 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_amd64_v1/dingo +0 -0
- 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 -164
- package/ledger/chainsync.go +0 -504
- package/ledger/delta.go +0 -99
- 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 -166
- 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 -258
- package/ledger/slot.go +0 -127
- package/ledger/slot_test.go +0 -147
- package/ledger/state.go +0 -821
- 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
|
@@ -1,118 +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 plugin
|
|
16
|
-
|
|
17
|
-
import (
|
|
18
|
-
"flag"
|
|
19
|
-
"fmt"
|
|
20
|
-
)
|
|
21
|
-
|
|
22
|
-
type PluginType int
|
|
23
|
-
|
|
24
|
-
const (
|
|
25
|
-
PluginTypeMetadata PluginType = 1
|
|
26
|
-
PluginTypeBlob PluginType = 2
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
func PluginTypeName(pluginType PluginType) string {
|
|
30
|
-
switch pluginType {
|
|
31
|
-
case PluginTypeMetadata:
|
|
32
|
-
return "metadata"
|
|
33
|
-
case PluginTypeBlob:
|
|
34
|
-
return "blob"
|
|
35
|
-
default:
|
|
36
|
-
return ""
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
type PluginEntry struct {
|
|
41
|
-
Type PluginType
|
|
42
|
-
Name string
|
|
43
|
-
Description string
|
|
44
|
-
Options []PluginOption
|
|
45
|
-
NewFromOptionsFunc func() Plugin
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
var pluginEntries []PluginEntry
|
|
49
|
-
|
|
50
|
-
func Register(pluginEntry PluginEntry) {
|
|
51
|
-
pluginEntries = append(pluginEntries, pluginEntry)
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
func PopulateCmdlineOptions(fs *flag.FlagSet) error {
|
|
55
|
-
for _, plugin := range pluginEntries {
|
|
56
|
-
for _, option := range plugin.Options {
|
|
57
|
-
if err := option.AddToFlagSet(fs, PluginTypeName(plugin.Type), plugin.Name); err != nil {
|
|
58
|
-
return err
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
return nil
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
func ProcessEnvVars() error {
|
|
66
|
-
for _, plugin := range pluginEntries {
|
|
67
|
-
// Generate env var prefix based on plugin type and name
|
|
68
|
-
envVarPrefix := fmt.Sprintf(
|
|
69
|
-
"%s-%s-",
|
|
70
|
-
PluginTypeName(plugin.Type),
|
|
71
|
-
plugin.Name,
|
|
72
|
-
)
|
|
73
|
-
for _, option := range plugin.Options {
|
|
74
|
-
if err := option.ProcessEnvVars(envVarPrefix); err != nil {
|
|
75
|
-
return err
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
return nil
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
func ProcessConfig(
|
|
83
|
-
pluginConfig map[string]map[string]map[interface{}]interface{},
|
|
84
|
-
) error {
|
|
85
|
-
for _, plugin := range pluginEntries {
|
|
86
|
-
if pluginTypeData, ok := pluginConfig[PluginTypeName(plugin.Type)]; ok {
|
|
87
|
-
if pluginData, ok := pluginTypeData[plugin.Name]; ok {
|
|
88
|
-
for _, option := range plugin.Options {
|
|
89
|
-
if err := option.ProcessConfig(pluginData); err != nil {
|
|
90
|
-
return err
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return nil
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
func GetPlugins(pluginType PluginType) []PluginEntry {
|
|
100
|
-
ret := []PluginEntry{}
|
|
101
|
-
for _, plugin := range pluginEntries {
|
|
102
|
-
if plugin.Type == pluginType {
|
|
103
|
-
ret = append(ret, plugin)
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
return ret
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
func GetPlugin(pluginType PluginType, name string) Plugin {
|
|
110
|
-
for _, plugin := range pluginEntries {
|
|
111
|
-
if plugin.Type == pluginType {
|
|
112
|
-
if plugin.Name == name {
|
|
113
|
-
return plugin.NewFromOptionsFunc()
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
return nil
|
|
118
|
-
}
|
package/database/pparams.go
DELETED
|
@@ -1,145 +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 database
|
|
16
|
-
|
|
17
|
-
import (
|
|
18
|
-
"fmt"
|
|
19
|
-
|
|
20
|
-
"github.com/blinklabs-io/gouroboros/cbor"
|
|
21
|
-
lcommon "github.com/blinklabs-io/gouroboros/ledger/common"
|
|
22
|
-
)
|
|
23
|
-
|
|
24
|
-
func (d *Database) GetPParams(
|
|
25
|
-
epoch uint64,
|
|
26
|
-
decodeFunc func([]byte) (lcommon.ProtocolParameters, error),
|
|
27
|
-
txn *Txn,
|
|
28
|
-
) (lcommon.ProtocolParameters, error) {
|
|
29
|
-
var ret lcommon.ProtocolParameters
|
|
30
|
-
var err error
|
|
31
|
-
if txn == nil {
|
|
32
|
-
pparams, ppErr := d.metadata.GetPParams(epoch, nil)
|
|
33
|
-
if err != nil {
|
|
34
|
-
return ret, ppErr
|
|
35
|
-
}
|
|
36
|
-
if len(pparams) == 0 {
|
|
37
|
-
return ret, nil
|
|
38
|
-
}
|
|
39
|
-
// pparams is ordered, so grab the first
|
|
40
|
-
tmpPParams := pparams[0]
|
|
41
|
-
ret, err = decodeFunc(tmpPParams.Cbor)
|
|
42
|
-
} else {
|
|
43
|
-
pparams, ppErr := d.metadata.GetPParams(epoch, txn.Metadata())
|
|
44
|
-
if err != nil {
|
|
45
|
-
return ret, ppErr
|
|
46
|
-
}
|
|
47
|
-
if len(pparams) == 0 {
|
|
48
|
-
return ret, nil
|
|
49
|
-
}
|
|
50
|
-
// pparams is ordered, so grab the first
|
|
51
|
-
tmpPParams := pparams[0]
|
|
52
|
-
ret, err = decodeFunc(tmpPParams.Cbor)
|
|
53
|
-
}
|
|
54
|
-
return ret, err
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
func (d *Database) SetPParams(
|
|
58
|
-
params []byte,
|
|
59
|
-
slot, epoch uint64,
|
|
60
|
-
era uint,
|
|
61
|
-
txn *Txn,
|
|
62
|
-
) error {
|
|
63
|
-
if txn == nil {
|
|
64
|
-
err := d.metadata.SetPParams(params, slot, epoch, era, nil)
|
|
65
|
-
if err != nil {
|
|
66
|
-
return err
|
|
67
|
-
}
|
|
68
|
-
} else {
|
|
69
|
-
err := d.metadata.SetPParams(params, slot, epoch, era, txn.Metadata())
|
|
70
|
-
if err != nil {
|
|
71
|
-
return err
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return nil
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
func (d *Database) ApplyPParamUpdates(
|
|
78
|
-
slot, epoch uint64,
|
|
79
|
-
era uint,
|
|
80
|
-
currentPParams *lcommon.ProtocolParameters,
|
|
81
|
-
decodeFunc func([]byte) (any, error),
|
|
82
|
-
updateFunc func(lcommon.ProtocolParameters, any) (lcommon.ProtocolParameters, error),
|
|
83
|
-
txn *Txn,
|
|
84
|
-
) error {
|
|
85
|
-
// Check for pparam updates that apply at the end of the epoch
|
|
86
|
-
pparamUpdates, err := d.metadata.GetPParamUpdates(epoch, txn.Metadata())
|
|
87
|
-
if err != nil {
|
|
88
|
-
return err
|
|
89
|
-
}
|
|
90
|
-
if len(pparamUpdates) == 0 {
|
|
91
|
-
// nothing to do
|
|
92
|
-
return nil
|
|
93
|
-
}
|
|
94
|
-
// We only want the latest for the epoch
|
|
95
|
-
pparamUpdate := pparamUpdates[0]
|
|
96
|
-
tmpPParamUpdate, err := decodeFunc(pparamUpdate.Cbor)
|
|
97
|
-
if err != nil {
|
|
98
|
-
return err
|
|
99
|
-
}
|
|
100
|
-
// Update current pparams
|
|
101
|
-
newPParams, err := updateFunc(
|
|
102
|
-
*currentPParams,
|
|
103
|
-
tmpPParamUpdate,
|
|
104
|
-
)
|
|
105
|
-
if err != nil {
|
|
106
|
-
return err
|
|
107
|
-
}
|
|
108
|
-
*currentPParams = newPParams
|
|
109
|
-
d.logger.Debug(
|
|
110
|
-
"updated protocol params",
|
|
111
|
-
"pparams",
|
|
112
|
-
fmt.Sprintf("%#v", currentPParams),
|
|
113
|
-
)
|
|
114
|
-
// Write pparams update to DB
|
|
115
|
-
pparamsCbor, err := cbor.Encode(¤tPParams)
|
|
116
|
-
if err != nil {
|
|
117
|
-
return err
|
|
118
|
-
}
|
|
119
|
-
return d.metadata.SetPParams(
|
|
120
|
-
pparamsCbor,
|
|
121
|
-
slot,
|
|
122
|
-
uint64(epoch+1),
|
|
123
|
-
era,
|
|
124
|
-
txn.Metadata(),
|
|
125
|
-
)
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
func (d *Database) SetPParamUpdate(
|
|
129
|
-
genesis, params []byte,
|
|
130
|
-
slot, epoch uint64,
|
|
131
|
-
txn *Txn,
|
|
132
|
-
) error {
|
|
133
|
-
if txn == nil {
|
|
134
|
-
err := d.metadata.SetPParamUpdate(genesis, params, slot, epoch, nil)
|
|
135
|
-
if err != nil {
|
|
136
|
-
return err
|
|
137
|
-
}
|
|
138
|
-
} else {
|
|
139
|
-
err := d.metadata.SetPParamUpdate(genesis, params, slot, epoch, txn.Metadata())
|
|
140
|
-
if err != nil {
|
|
141
|
-
return err
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
return nil
|
|
145
|
-
}
|
package/database/tip.go
DELETED
|
@@ -1,45 +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 database
|
|
16
|
-
|
|
17
|
-
import ochainsync "github.com/blinklabs-io/gouroboros/protocol/chainsync"
|
|
18
|
-
|
|
19
|
-
// GetTip returns the current tip as represented by the protocol
|
|
20
|
-
func (d *Database) GetTip(txn *Txn) (ochainsync.Tip, error) {
|
|
21
|
-
tmpTip := ochainsync.Tip{}
|
|
22
|
-
if txn == nil {
|
|
23
|
-
tip, err := d.metadata.GetTip(nil)
|
|
24
|
-
if err != nil {
|
|
25
|
-
return tmpTip, err
|
|
26
|
-
}
|
|
27
|
-
tmpTip = tip
|
|
28
|
-
} else {
|
|
29
|
-
tip, err := d.metadata.GetTip(txn.Metadata())
|
|
30
|
-
if err != nil {
|
|
31
|
-
return tmpTip, err
|
|
32
|
-
}
|
|
33
|
-
tmpTip = tip
|
|
34
|
-
}
|
|
35
|
-
return tmpTip, nil
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// SetTip saves the current tip
|
|
39
|
-
func (d *Database) SetTip(tip ochainsync.Tip, txn *Txn) error {
|
|
40
|
-
if txn == nil {
|
|
41
|
-
return d.metadata.SetTip(tip, nil)
|
|
42
|
-
} else {
|
|
43
|
-
return d.metadata.SetTip(tip, txn.Metadata())
|
|
44
|
-
}
|
|
45
|
-
}
|
package/database/txn.go
DELETED
|
@@ -1,147 +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 database
|
|
16
|
-
|
|
17
|
-
import (
|
|
18
|
-
"fmt"
|
|
19
|
-
"sync"
|
|
20
|
-
"time"
|
|
21
|
-
|
|
22
|
-
"github.com/dgraph-io/badger/v4"
|
|
23
|
-
"gorm.io/gorm"
|
|
24
|
-
)
|
|
25
|
-
|
|
26
|
-
// Txn is a wrapper around the transaction objects for the underlying DB engines
|
|
27
|
-
type Txn struct {
|
|
28
|
-
lock sync.Mutex
|
|
29
|
-
finished bool
|
|
30
|
-
db *Database
|
|
31
|
-
readWrite bool
|
|
32
|
-
blobTxn *badger.Txn
|
|
33
|
-
metadataTxn *gorm.DB
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
func NewTxn(db *Database, readWrite bool) *Txn {
|
|
37
|
-
return &Txn{
|
|
38
|
-
db: db,
|
|
39
|
-
readWrite: readWrite,
|
|
40
|
-
blobTxn: db.Blob().NewTransaction(readWrite),
|
|
41
|
-
metadataTxn: db.Metadata().Transaction(),
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
func NewBlobOnlyTxn(db *Database, readWrite bool) *Txn {
|
|
46
|
-
return &Txn{
|
|
47
|
-
db: db,
|
|
48
|
-
readWrite: readWrite,
|
|
49
|
-
blobTxn: db.Blob().NewTransaction(readWrite),
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
func NewMetadataOnlyTxn(db *Database, readWrite bool) *Txn {
|
|
54
|
-
return &Txn{
|
|
55
|
-
db: db,
|
|
56
|
-
readWrite: readWrite,
|
|
57
|
-
metadataTxn: db.Metadata().Transaction(),
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
func (t *Txn) DB() *Database {
|
|
62
|
-
return t.db
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
func (t *Txn) Metadata() *gorm.DB {
|
|
66
|
-
return t.metadataTxn
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
func (t *Txn) Blob() *badger.Txn {
|
|
70
|
-
return t.blobTxn
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// Do executes the specified function in the context of the transaction. Any errors returned will result
|
|
74
|
-
// in the transaction being rolled back
|
|
75
|
-
func (t *Txn) Do(fn func(*Txn) error) error {
|
|
76
|
-
if err := fn(t); err != nil {
|
|
77
|
-
if err2 := t.Rollback(); err2 != nil {
|
|
78
|
-
return fmt.Errorf(
|
|
79
|
-
"rollback failed: %w: original error: %w",
|
|
80
|
-
err2,
|
|
81
|
-
err,
|
|
82
|
-
)
|
|
83
|
-
}
|
|
84
|
-
return err
|
|
85
|
-
}
|
|
86
|
-
if err := t.Commit(); err != nil {
|
|
87
|
-
return fmt.Errorf("commit failed: %w", err)
|
|
88
|
-
}
|
|
89
|
-
return nil
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
func (t *Txn) Commit() error {
|
|
93
|
-
t.lock.Lock()
|
|
94
|
-
defer t.lock.Unlock()
|
|
95
|
-
if t.finished {
|
|
96
|
-
return nil
|
|
97
|
-
}
|
|
98
|
-
// No need to commit for read-only, but we do want to free up resources
|
|
99
|
-
if !t.readWrite {
|
|
100
|
-
return t.rollback()
|
|
101
|
-
}
|
|
102
|
-
// Update the commit timestamp in both DBs if using both
|
|
103
|
-
if t.blobTxn != nil && t.metadataTxn != nil {
|
|
104
|
-
commitTimestamp := time.Now().UnixMilli()
|
|
105
|
-
if err := t.db.updateCommitTimestamp(t, commitTimestamp); err != nil {
|
|
106
|
-
return err
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
// Commit sqlite transaction
|
|
110
|
-
if t.metadataTxn != nil {
|
|
111
|
-
if result := t.metadataTxn.Commit(); result.Error != nil {
|
|
112
|
-
// Failed to commit metadata DB, so discard blob txn
|
|
113
|
-
t.blobTxn.Discard()
|
|
114
|
-
return result.Error
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
// Commit badger transaction
|
|
118
|
-
if t.blobTxn != nil {
|
|
119
|
-
if err := t.blobTxn.Commit(); err != nil {
|
|
120
|
-
return err
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
t.finished = true
|
|
124
|
-
return nil
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
func (t *Txn) Rollback() error {
|
|
128
|
-
t.lock.Lock()
|
|
129
|
-
defer t.lock.Unlock()
|
|
130
|
-
return t.rollback()
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
func (t *Txn) rollback() error {
|
|
134
|
-
if t.finished {
|
|
135
|
-
return nil
|
|
136
|
-
}
|
|
137
|
-
if t.blobTxn != nil {
|
|
138
|
-
t.blobTxn.Discard()
|
|
139
|
-
}
|
|
140
|
-
if t.metadataTxn != nil {
|
|
141
|
-
if result := t.metadataTxn.Rollback(); result.Error != nil {
|
|
142
|
-
return result.Error
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
t.finished = true
|
|
146
|
-
return nil
|
|
147
|
-
}
|
package/database/types/types.go
DELETED
|
@@ -1,74 +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 types
|
|
16
|
-
|
|
17
|
-
import (
|
|
18
|
-
"database/sql/driver"
|
|
19
|
-
"fmt"
|
|
20
|
-
"math/big"
|
|
21
|
-
"strconv"
|
|
22
|
-
)
|
|
23
|
-
|
|
24
|
-
//nolint:recvcheck
|
|
25
|
-
type Rat struct {
|
|
26
|
-
*big.Rat
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
func (r Rat) Value() (driver.Value, error) {
|
|
30
|
-
if r.Rat == nil {
|
|
31
|
-
return "", nil
|
|
32
|
-
}
|
|
33
|
-
return r.String(), nil
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
func (r *Rat) Scan(val any) error {
|
|
37
|
-
if r.Rat == nil {
|
|
38
|
-
r.Rat = new(big.Rat)
|
|
39
|
-
}
|
|
40
|
-
v, ok := val.(string)
|
|
41
|
-
if !ok {
|
|
42
|
-
return fmt.Errorf(
|
|
43
|
-
"value was not expected type, wanted string, got %T",
|
|
44
|
-
val,
|
|
45
|
-
)
|
|
46
|
-
}
|
|
47
|
-
if _, ok := r.SetString(v); !ok {
|
|
48
|
-
return fmt.Errorf("failed to set big.Rat value from string: %s", v)
|
|
49
|
-
}
|
|
50
|
-
return nil
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
//nolint:recvcheck
|
|
54
|
-
type Uint64 uint64
|
|
55
|
-
|
|
56
|
-
func (u Uint64) Value() (driver.Value, error) {
|
|
57
|
-
return strconv.FormatUint(uint64(u), 10), nil
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
func (u *Uint64) Scan(val any) error {
|
|
61
|
-
v, ok := val.(string)
|
|
62
|
-
if !ok {
|
|
63
|
-
return fmt.Errorf(
|
|
64
|
-
"value was not expected type, wanted string, got %T",
|
|
65
|
-
val,
|
|
66
|
-
)
|
|
67
|
-
}
|
|
68
|
-
tmpUint, err := strconv.ParseUint(v, 10, 64)
|
|
69
|
-
if err != nil {
|
|
70
|
-
return err
|
|
71
|
-
}
|
|
72
|
-
*u = Uint64(tmpUint)
|
|
73
|
-
return nil
|
|
74
|
-
}
|
|
@@ -1,83 +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 types_test
|
|
16
|
-
|
|
17
|
-
import (
|
|
18
|
-
"database/sql"
|
|
19
|
-
"database/sql/driver"
|
|
20
|
-
"math/big"
|
|
21
|
-
"reflect"
|
|
22
|
-
"testing"
|
|
23
|
-
|
|
24
|
-
"github.com/blinklabs-io/dingo/database/types"
|
|
25
|
-
)
|
|
26
|
-
|
|
27
|
-
func TestTypesScanValue(t *testing.T) {
|
|
28
|
-
testDefs := []struct {
|
|
29
|
-
origValue any
|
|
30
|
-
expectedValue any
|
|
31
|
-
}{
|
|
32
|
-
{
|
|
33
|
-
origValue: func(v types.Uint64) *types.Uint64 { return &v }(
|
|
34
|
-
types.Uint64(123),
|
|
35
|
-
),
|
|
36
|
-
expectedValue: "123",
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
origValue: func(v types.Rat) *types.Rat { return &v }(
|
|
40
|
-
types.Rat{
|
|
41
|
-
Rat: big.NewRat(3, 5),
|
|
42
|
-
},
|
|
43
|
-
),
|
|
44
|
-
expectedValue: "3/5",
|
|
45
|
-
},
|
|
46
|
-
}
|
|
47
|
-
var ok bool
|
|
48
|
-
var tmpScanner sql.Scanner
|
|
49
|
-
var tmpValuer driver.Valuer
|
|
50
|
-
for _, testDef := range testDefs {
|
|
51
|
-
tmpValuer, ok = testDef.origValue.(driver.Valuer)
|
|
52
|
-
if !ok {
|
|
53
|
-
t.Fatalf("test original value does not implement driver.Valuer")
|
|
54
|
-
}
|
|
55
|
-
valueOut, err := tmpValuer.Value()
|
|
56
|
-
if err != nil {
|
|
57
|
-
t.Fatalf("unexpected error: %s", err)
|
|
58
|
-
}
|
|
59
|
-
if !reflect.DeepEqual(valueOut, testDef.expectedValue) {
|
|
60
|
-
t.Fatalf(
|
|
61
|
-
"did not get expected value from Value(): got %#v, expected %#v",
|
|
62
|
-
valueOut,
|
|
63
|
-
testDef.expectedValue,
|
|
64
|
-
)
|
|
65
|
-
}
|
|
66
|
-
tmpScanner, ok = testDef.origValue.(sql.Scanner)
|
|
67
|
-
if !ok {
|
|
68
|
-
t.Fatalf(
|
|
69
|
-
"test original value does not implement sql.Scanner (it must be a pointer)",
|
|
70
|
-
)
|
|
71
|
-
}
|
|
72
|
-
if err := tmpScanner.Scan(valueOut); err != nil {
|
|
73
|
-
t.Fatalf("unexpected error: %s", err)
|
|
74
|
-
}
|
|
75
|
-
if !reflect.DeepEqual(tmpScanner, testDef.origValue) {
|
|
76
|
-
t.Fatalf(
|
|
77
|
-
"did not get expected value after Scan(): got %#v, expected %#v",
|
|
78
|
-
tmpScanner,
|
|
79
|
-
testDef.origValue,
|
|
80
|
-
)
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|