Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: rename state package to ledger #617

Merged
merged 1 commit into from
Apr 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions blockfetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import (
"time"

"github.com/blinklabs-io/dingo/event"
"github.com/blinklabs-io/dingo/state"
"github.com/blinklabs-io/dingo/ledger"
ouroboros "github.com/blinklabs-io/gouroboros"
"github.com/blinklabs-io/gouroboros/ledger"
gledger "github.com/blinklabs-io/gouroboros/ledger"
"github.com/blinklabs-io/gouroboros/protocol/blockfetch"
ocommon "github.com/blinklabs-io/gouroboros/protocol/common"
)
Expand Down Expand Up @@ -106,14 +106,14 @@ func (n *Node) blockfetchClientRequestRange(
func (n *Node) blockfetchClientBlock(
ctx blockfetch.CallbackContext,
blockType uint,
block ledger.Block,
block gledger.Block,
) error {
// Generate event
n.eventBus.Publish(
state.BlockfetchEventType,
ledger.BlockfetchEventType,
event.NewEvent(
state.BlockfetchEventType,
state.BlockfetchEvent{
ledger.BlockfetchEventType,
ledger.BlockfetchEvent{
Point: ocommon.NewPoint(block.SlotNumber(), block.Hash().Bytes()),
Type: blockType,
Block: block,
Expand All @@ -128,10 +128,10 @@ func (n *Node) blockfetchClientBatchDone(
) error {
// Generate event
n.eventBus.Publish(
state.BlockfetchEventType,
ledger.BlockfetchEventType,
event.NewEvent(
state.BlockfetchEventType,
state.BlockfetchEvent{
ledger.BlockfetchEventType,
ledger.BlockfetchEvent{
ConnectionId: ctx.ConnectionId,
BatchDone: true,
},
Expand Down
18 changes: 9 additions & 9 deletions chainsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import (
"fmt"

"github.com/blinklabs-io/dingo/event"
"github.com/blinklabs-io/dingo/state"
"github.com/blinklabs-io/dingo/ledger"
ouroboros "github.com/blinklabs-io/gouroboros"
"github.com/blinklabs-io/gouroboros/ledger"
gledger "github.com/blinklabs-io/gouroboros/ledger"
ochainsync "github.com/blinklabs-io/gouroboros/protocol/chainsync"
ocommon "github.com/blinklabs-io/gouroboros/protocol/common"
)
Expand Down Expand Up @@ -180,10 +180,10 @@ func (n *Node) chainsyncClientRollBackward(
) error {
// Generate event
n.eventBus.Publish(
state.ChainsyncEventType,
ledger.ChainsyncEventType,
event.NewEvent(
state.ChainsyncEventType,
state.ChainsyncEvent{
ledger.ChainsyncEventType,
ledger.ChainsyncEvent{
Rollback: true,
Point: point,
Tip: tip,
Expand All @@ -200,14 +200,14 @@ func (n *Node) chainsyncClientRollForward(
tip ochainsync.Tip,
) error {
switch v := blockData.(type) {
case ledger.BlockHeader:
case gledger.BlockHeader:
blockSlot := v.SlotNumber()
blockHash := v.Hash().Bytes()
n.eventBus.Publish(
state.ChainsyncEventType,
ledger.ChainsyncEventType,
event.NewEvent(
state.ChainsyncEventType,
state.ChainsyncEvent{
ledger.ChainsyncEventType,
ledger.ChainsyncEvent{
ConnectionId: ctx.ConnectionId,
Point: ocommon.NewPoint(blockSlot, blockHash),
Type: blockType,
Expand Down
6 changes: 3 additions & 3 deletions chainsync/chainsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

"github.com/blinklabs-io/dingo/chain"
"github.com/blinklabs-io/dingo/event"
"github.com/blinklabs-io/dingo/state"
"github.com/blinklabs-io/dingo/ledger"
ouroboros "github.com/blinklabs-io/gouroboros"
"github.com/blinklabs-io/gouroboros/connection"
ocommon "github.com/blinklabs-io/gouroboros/protocol/common"
Expand All @@ -34,14 +34,14 @@ type ChainsyncClientState struct {
type State struct {
sync.Mutex
eventBus *event.EventBus
ledgerState *state.LedgerState
ledgerState *ledger.LedgerState
clients map[ouroboros.ConnectionId]*ChainsyncClientState
clientConnId *ouroboros.ConnectionId // TODO: replace with handling of multiple chainsync clients (#385)
}

func NewState(
eventBus *event.EventBus,
ledgerState *state.LedgerState,
ledgerState *ledger.LedgerState,
) *State {
s := &State{
eventBus: eventBus,
Expand Down
12 changes: 6 additions & 6 deletions internal/node/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (
"github.com/blinklabs-io/dingo/database/immutable"
"github.com/blinklabs-io/dingo/event"
"github.com/blinklabs-io/dingo/internal/config"
"github.com/blinklabs-io/dingo/state"
"github.com/blinklabs-io/gouroboros/ledger"
"github.com/blinklabs-io/dingo/ledger"
gledger "github.com/blinklabs-io/gouroboros/ledger"
)

func Load(logger *slog.Logger, immutableDir string) error {
Expand All @@ -50,8 +50,8 @@ func Load(logger *slog.Logger, immutableDir string) error {
}
// Load state
eventBus := event.NewEventBus(nil)
ls, err := state.NewLedgerState(
state.LedgerStateConfig{
ls, err := ledger.NewLedgerState(
ledger.LedgerStateConfig{
DataDir: cfg.DatabasePath,
Logger: logger,
CardanoNodeConfig: nodeCfg,
Expand Down Expand Up @@ -80,7 +80,7 @@ func Load(logger *slog.Logger, immutableDir string) error {
return fmt.Errorf("failed to get immutable DB iterator: %w", err)
}
var blocksCopied int
blockBatch := make([]ledger.Block, 0, 500)
blockBatch := make([]gledger.Block, 0, 500)
for {
for {
next, err := iter.Next()
Expand All @@ -91,7 +91,7 @@ func Load(logger *slog.Logger, immutableDir string) error {
if next == nil {
break
}
tmpBlock, err := ledger.NewBlockFromCbor(next.Type, next.Cbor)
tmpBlock, err := gledger.NewBlockFromCbor(next.Type, next.Cbor)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion state/certs.go → ledger/certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package state
package ledger

import (
"fmt"
Expand Down
4 changes: 2 additions & 2 deletions state/chainsync.go → ledger/chainsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package state
package ledger

import (
"encoding/hex"
Expand All @@ -25,7 +25,7 @@ import (
"github.com/blinklabs-io/dingo/chain"
"github.com/blinklabs-io/dingo/database"
"github.com/blinklabs-io/dingo/event"
"github.com/blinklabs-io/dingo/state/eras"
"github.com/blinklabs-io/dingo/ledger/eras"
ouroboros "github.com/blinklabs-io/gouroboros"
"github.com/blinklabs-io/gouroboros/cbor"
"github.com/blinklabs-io/gouroboros/ledger"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion state/error.go → ledger/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package state
package ledger

import "errors"

Expand Down
2 changes: 1 addition & 1 deletion state/event.go → ledger/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package state
package ledger

import (
"github.com/blinklabs-io/dingo/event"
Expand Down
2 changes: 1 addition & 1 deletion state/metrics.go → ledger/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package state
package ledger

import (
"github.com/prometheus/client_golang/prometheus"
Expand Down
4 changes: 2 additions & 2 deletions state/queries.go → ledger/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package state
package ledger

import (
"errors"
"fmt"
"math/big"

"github.com/blinklabs-io/dingo/database"
"github.com/blinklabs-io/dingo/state/eras"
"github.com/blinklabs-io/dingo/ledger/eras"
"github.com/blinklabs-io/gouroboros/cbor"
"github.com/blinklabs-io/gouroboros/ledger"
olocalstatequery "github.com/blinklabs-io/gouroboros/protocol/localstatequery"
Expand Down
4 changes: 2 additions & 2 deletions state/state.go → ledger/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package state
package ledger

import (
"encoding/hex"
Expand All @@ -28,7 +28,7 @@ import (
"github.com/blinklabs-io/dingo/config/cardano"
"github.com/blinklabs-io/dingo/database"
"github.com/blinklabs-io/dingo/event"
"github.com/blinklabs-io/dingo/state/eras"
"github.com/blinklabs-io/dingo/ledger/eras"
ouroboros "github.com/blinklabs-io/gouroboros"
"github.com/blinklabs-io/gouroboros/cbor"
"github.com/blinklabs-io/gouroboros/ledger"
Expand Down
2 changes: 1 addition & 1 deletion state/view.go → ledger/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package state
package ledger

import (
"github.com/blinklabs-io/dingo/database"
Expand Down
12 changes: 6 additions & 6 deletions mempool/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import (

"github.com/blinklabs-io/dingo/chain"
"github.com/blinklabs-io/dingo/event"
"github.com/blinklabs-io/dingo/state"
"github.com/blinklabs-io/dingo/ledger"
ouroboros "github.com/blinklabs-io/gouroboros"
"github.com/blinklabs-io/gouroboros/ledger"
gledger "github.com/blinklabs-io/gouroboros/ledger"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
Expand Down Expand Up @@ -56,7 +56,7 @@ type Mempool struct {
sync.RWMutex
logger *slog.Logger
eventBus *event.EventBus
ledgerState *state.LedgerState
ledgerState *ledger.LedgerState
consumers map[ouroboros.ConnectionId]*MempoolConsumer
consumersMutex sync.Mutex
transactions []*MempoolTransaction
Expand All @@ -71,7 +71,7 @@ func NewMempool(
logger *slog.Logger,
eventBus *event.EventBus,
promRegistry prometheus.Registerer,
ledgerState *state.LedgerState,
ledgerState *ledger.LedgerState,
) *Mempool {
m := &Mempool{
eventBus: eventBus,
Expand Down Expand Up @@ -153,7 +153,7 @@ func (m *Mempool) processChainEvents() {
for i := len(m.transactions) - 1; i >= 0; i-- {
tx := m.transactions[i]
// Decode transaction
tmpTx, err := ledger.NewTransactionFromCbor(tx.Type, tx.Cbor)
tmpTx, err := gledger.NewTransactionFromCbor(tx.Type, tx.Cbor)
if err != nil {
m.removeTransactionByIndex(i)
m.logger.Error(
Expand Down Expand Up @@ -181,7 +181,7 @@ func (m *Mempool) processChainEvents() {

func (m *Mempool) AddTransaction(txType uint, txBytes []byte) error {
// Decode transaction
tmpTx, err := ledger.NewTransactionFromCbor(txType, txBytes)
tmpTx, err := gledger.NewTransactionFromCbor(txType, txBytes)
if err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions node.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import (
"github.com/blinklabs-io/dingo/chainsync"
"github.com/blinklabs-io/dingo/connmanager"
"github.com/blinklabs-io/dingo/event"
"github.com/blinklabs-io/dingo/ledger"
"github.com/blinklabs-io/dingo/mempool"
"github.com/blinklabs-io/dingo/peergov"
"github.com/blinklabs-io/dingo/state"
"github.com/blinklabs-io/dingo/utxorpc"
ouroboros "github.com/blinklabs-io/gouroboros"
oblockfetch "github.com/blinklabs-io/gouroboros/protocol/blockfetch"
Expand All @@ -44,7 +44,7 @@ type Node struct {
chainsyncState *chainsync.State
eventBus *event.EventBus
mempool *mempool.Mempool
ledgerState *state.LedgerState
ledgerState *ledger.LedgerState
utxorpc *utxorpc.Utxorpc
shutdownFuncs []func(context.Context) error
}
Expand Down Expand Up @@ -72,8 +72,8 @@ func (n *Node) Run() error {
}
}
// Load state
state, err := state.NewLedgerState(
state.LedgerStateConfig{
state, err := ledger.NewLedgerState(
ledger.LedgerStateConfig{
DataDir: n.config.dataDir,
EventBus: n.eventBus,
Logger: n.config.logger,
Expand Down
Loading
Loading