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

chore(deps): update blinklabs-io/gouroboros to v0.116.0 #586

Merged
merged 1 commit into from
Apr 1, 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
7 changes: 1 addition & 6 deletions blockfetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package dingo

import (
"encoding/hex"
"fmt"
"time"

Expand Down Expand Up @@ -111,16 +110,12 @@ func (n *Node) blockfetchClientBlock(
block ledger.Block,
) error {
// Generate event
blkHash, err := hex.DecodeString(block.Hash())
if err != nil {
return fmt.Errorf("decode block hash: %w", err)
}
n.eventBus.Publish(
state.BlockfetchEventType,
event.NewEvent(
state.BlockfetchEventType,
state.BlockfetchEvent{
Point: ocommon.NewPoint(block.SlotNumber(), blkHash),
Point: ocommon.NewPoint(block.SlotNumber(), block.Hash().Bytes()),
Type: blockType,
Block: block,
},
Expand Down
22 changes: 6 additions & 16 deletions chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package chain

import (
"encoding/hex"
"errors"
"fmt"
"slices"
Expand Down Expand Up @@ -98,30 +97,21 @@ func (c *Chain) Tip() ochainsync.Tip {
func (c *Chain) AddBlock(block ledger.Block, blockNonce []byte, txn *database.Txn) error {
c.mutex.Lock()
defer c.mutex.Unlock()
// Get block hash and previous hash
hashBytes, err := hex.DecodeString(block.Hash())
if err != nil {
return err
}
prevHashBytes, err := hex.DecodeString(block.PrevHash())
if err != nil {
return err
}
// Check that this block fits on the current chain tip
if c.tipBlockIndex >= initialBlockIndex {
if string(prevHashBytes) != string(c.currentTip.Point.Hash) {
if string(block.PrevHash().Bytes()) != string(c.currentTip.Point.Hash) {
return fmt.Errorf(
"block %s (with prev hash %x) does not fit on current chain tip (%x)",
block.Hash(),
prevHashBytes,
"block %s (with prev hash %s) does not fit on current chain tip (%x)",
block.Hash().String(),
block.PrevHash().String(),
c.currentTip.Point.Hash,
)
}
}
// Build new block record
tmpPoint := ocommon.NewPoint(
block.SlotNumber(),
hashBytes,
block.Hash().Bytes(),
)
newBlockIndex := c.tipBlockIndex + 1
tmpBlock := database.Block{
Expand All @@ -130,7 +120,7 @@ func (c *Chain) AddBlock(block ledger.Block, blockNonce []byte, txn *database.Tx
Hash: tmpPoint.Hash,
Number: block.BlockNumber(),
Type: uint(block.Type()), //nolint:gosec
PrevHash: prevHashBytes,
PrevHash: block.PrevHash().Bytes(),
Nonce: blockNonce,
Cbor: block.Cbor(),
}
Expand Down
27 changes: 19 additions & 8 deletions chain/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/blinklabs-io/dingo/chain"
"github.com/blinklabs-io/dingo/event"
"github.com/blinklabs-io/gouroboros/ledger"
"github.com/blinklabs-io/gouroboros/ledger/common"
ocommon "github.com/blinklabs-io/gouroboros/protocol/common"
)

Expand All @@ -33,12 +34,20 @@ type MockBlock struct {
MockPrevHash string
}

func (b *MockBlock) Hash() string {
return b.MockHash
func (b *MockBlock) Hash() common.Blake2b256 {
hashBytes, err := hex.DecodeString(b.MockHash)
if err != nil {
panic("failed decoding hex: " + err.Error())
}
return common.NewBlake2b256(hashBytes)
}

func (b *MockBlock) PrevHash() string {
return b.MockPrevHash
func (b *MockBlock) PrevHash() common.Blake2b256 {
prevHashBytes, err := hex.DecodeString(b.MockPrevHash)
if err != nil {
panic("failed decoding hex: " + err.Error())
}
return common.NewBlake2b256(prevHashBytes)
}

func (b *MockBlock) SlotNumber() uint64 {
Expand All @@ -50,7 +59,7 @@ func (b *MockBlock) BlockNumber() uint64 {
}

func TestChainBasic(t *testing.T) {
testHashPrefix := "47442c8830c700ecb099064ee1b038ed6fd254133f582e906a4bc3fd"
testHashPrefix := "000047442c8830c700ecb099064ee1b038ed6fd254133f582e906a4bc3fd"
testNonce := []byte{0xab, 0xcd, 0xef, 0x01}
testBlocks := []*MockBlock{
{
Expand Down Expand Up @@ -122,9 +131,11 @@ func TestChainBasic(t *testing.T) {
if nextHashHex != testBlock.MockHash {
t.Fatalf("did not get expected block from iterator: got hash %s, expected %s", nextHashHex, testBlock.MockHash)
}
nextPrevHashHex := hex.EncodeToString(nextBlock.PrevHash)
if nextPrevHashHex != testBlock.MockPrevHash {
t.Fatalf("did not get expected block from iterator: got prev hash %s, expected %s", nextPrevHashHex, testBlock.MockPrevHash)
if testBlock.MockPrevHash != "" {
nextPrevHashHex := hex.EncodeToString(nextBlock.PrevHash)
if nextPrevHashHex != testBlock.MockPrevHash {
t.Fatalf("did not get expected block from iterator: got prev hash %s, expected %s", nextPrevHashHex, testBlock.MockPrevHash)
}
}
if nextBlock.Slot != testBlock.MockSlot {
t.Fatalf("did not get expected block from iterator: got slot %d, expected %d", nextBlock.Slot, testBlock.MockSlot)
Expand Down
3 changes: 1 addition & 2 deletions chainsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package dingo

import (
"encoding/hex"
"fmt"

"github.com/blinklabs-io/dingo/event"
Expand Down Expand Up @@ -203,7 +202,7 @@ func (n *Node) chainsyncClientRollForward(
switch v := blockData.(type) {
case ledger.BlockHeader:
blockSlot := v.SlotNumber()
blockHash, _ := hex.DecodeString(v.Hash())
blockHash := v.Hash().Bytes()
n.eventBus.Publish(
state.ChainsyncEventType,
event.NewEvent(
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
connectrpc.com/connect v1.18.1
connectrpc.com/grpchealth v1.3.0
connectrpc.com/grpcreflect v1.3.0
github.com/blinklabs-io/gouroboros v0.115.2
github.com/blinklabs-io/gouroboros v0.116.0
github.com/blinklabs-io/ouroboros-mock v0.3.7
github.com/dgraph-io/badger/v4 v4.6.0
github.com/glebarez/sqlite v1.11.0
Expand Down Expand Up @@ -40,7 +40,7 @@ require (
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/dgraph-io/ristretto/v2 v2.1.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
github.com/fxamacker/cbor/v2 v2.8.0 // indirect
github.com/glebarez/go-sqlite v1.21.2 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4
github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/blinklabs-io/gouroboros v0.115.2 h1:qG6uu8yDQpJ4VYmiARdkOpfjvKw3r0MG4B6dFaZ8Rzc=
github.com/blinklabs-io/gouroboros v0.115.2/go.mod h1:E43ihaCCqNYMsTtdGbTv6Un0QVYcSXb3E/SbADJNBIM=
github.com/blinklabs-io/gouroboros v0.116.0 h1:B+2HUCdMgu1TRlME1Y1ds+nhzmgKLuJwdq7nfSJta08=
github.com/blinklabs-io/gouroboros v0.116.0/go.mod h1:g4e4aqLWcsRCgwk1KLq49CJF4uNq/ZXAp4Z63BbSo4o=
github.com/blinklabs-io/ouroboros-mock v0.3.7 h1:86FvD591XhdGk2BqQweRKfwc6Y6ll5Lunmo/RUehJ6o=
github.com/blinklabs-io/ouroboros-mock v0.3.7/go.mod h1:611xZgdWCxZsSaS5tjgxqjmWIkSpsM9eKuQAKozw+sk=
github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ=
Expand Down Expand Up @@ -59,8 +59,8 @@ github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkp
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/fxamacker/cbor/v2 v2.7.0 h1:iM5WgngdRBanHcxugY4JySA0nk1wZorNOpTgCMedv5E=
github.com/fxamacker/cbor/v2 v2.7.0/go.mod h1:pxXPTn3joSm21Gbwsv0w9OSA2y1HFR9qXEeXQVeNoDQ=
github.com/fxamacker/cbor/v2 v2.8.0 h1:fFtUGXUzXPHTIUdne5+zzMPTfffl3RD5qYnkY40vtxU=
github.com/fxamacker/cbor/v2 v2.8.0/go.mod h1:vM4b+DJCtHn+zz7h3FFp/hDAI9WNWCsZj23V5ytsSxQ=
github.com/glebarez/go-sqlite v1.21.2 h1:3a6LFC4sKahUunAmynQKLZceZCOzUthkRkEAl9gAXWo=
github.com/glebarez/go-sqlite v1.21.2/go.mod h1:sfxdZyhQjTM2Wry3gVYWaW072Ri1WMdWJi0k6+3382k=
github.com/glebarez/sqlite v1.11.0 h1:wSG0irqzP6VurnMEpFGer5Li19RpIRi2qvQz++w0GMw=
Expand Down
2 changes: 1 addition & 1 deletion mempool/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func (m *Mempool) AddTransaction(txType uint, txBytes []byte) error {
return err
}
// Build mempool entry
txHash := tmpTx.Hash()
txHash := tmpTx.Hash().String()
tx := MempoolTransaction{
Hash: txHash,
Type: txType,
Expand Down
2 changes: 1 addition & 1 deletion state/chainsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ func (ls *LedgerState) processTransaction(
)
if err != nil {
ls.config.Logger.Warn(
"TX " + tx.Hash() + " failed validation: " + err.Error(),
"TX " + tx.Hash().String() + " failed validation: " + err.Error(),
)
// return fmt.Errorf("TX validation failure: %w", err)
}
Expand Down
12 changes: 4 additions & 8 deletions state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,15 +481,11 @@ func (ls *LedgerState) ledgerProcessBlocks() {
func (ls *LedgerState) ledgerProcessBlock(txn *database.Txn, point ocommon.Point, block ledger.Block, nonce []byte) error {
// Check that we're processing things in order
if len(ls.currentTip.Point.Hash) > 0 {
prevHashBytes, err := hex.DecodeString(block.PrevHash())
if err != nil {
return err
}
if string(prevHashBytes) != string(ls.currentTip.Point.Hash) {
if string(block.PrevHash().Bytes()) != string(ls.currentTip.Point.Hash) {
return fmt.Errorf(
"block %s (with prev hash %x) does not fit on current chain tip (%x)",
block.Hash(),
prevHashBytes,
"block %s (with prev hash %s) does not fit on current chain tip (%x)",
block.Hash().String(),
block.PrevHash().String(),
ls.currentTip.Point.Hash,
)
}
Expand Down
2 changes: 1 addition & 1 deletion utxorpc/submit.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (s *submitServiceServer) WaitForTx(
for _, r := range ref {
refHash := hex.EncodeToString(r)
// Compare our hashes
if refHash == tx.Hash() {
if refHash == tx.Hash().String() {
// Send confirmation response
err := stream.Send(&submit.WaitForTxResponse{
Ref: r,
Expand Down