Skip to content
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
36 changes: 30 additions & 6 deletions ledger/byron/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,25 @@ func TestGenesisNonAvvmUtxos(t *testing.T) {
}
tmpUtxo := tmpGenesisUtxos[0]
if tmpUtxo.Id.Id().String() != expectedTxId {
t.Fatalf("did not get expected TxID: got %s, wanted %s", tmpUtxo.Id.Id().String(), expectedTxId)
t.Fatalf(
"did not get expected TxID: got %s, wanted %s",
tmpUtxo.Id.Id().String(),
expectedTxId,
)
}
if tmpUtxo.Output.Address().String() != testAddr {
t.Fatalf("did not get expected address: got %s, wanted %s", tmpUtxo.Output.Address().String(), testAddr)
t.Fatalf(
"did not get expected address: got %s, wanted %s",
tmpUtxo.Output.Address().String(),
testAddr,
)
}
if tmpUtxo.Output.Amount() != testAmount {
t.Fatalf("did not get expected amount: got %d, wanted %d", tmpUtxo.Output.Amount(), testAmount)
t.Fatalf(
"did not get expected amount: got %d, wanted %d",
tmpUtxo.Output.Amount(),
testAmount,
)
}
}

Expand Down Expand Up @@ -323,12 +335,24 @@ func TestGenesisAvvmUtxos(t *testing.T) {
}
tmpUtxo := tmpGenesisUtxos[0]
if tmpUtxo.Id.Id().String() != expectedTxId {
t.Fatalf("did not get expected TxID: got %s, wanted %s", tmpUtxo.Id.Id().String(), expectedTxId)
t.Fatalf(
"did not get expected TxID: got %s, wanted %s",
tmpUtxo.Id.Id().String(),
expectedTxId,
)
}
if tmpUtxo.Output.Address().String() != expectedAddr {
t.Fatalf("did not get expected address: got %s, wanted %s", tmpUtxo.Output.Address().String(), expectedAddr)
t.Fatalf(
"did not get expected address: got %s, wanted %s",
tmpUtxo.Output.Address().String(),
expectedAddr,
)
}
if tmpUtxo.Output.Amount() != testAmount {
t.Fatalf("did not get expected amount: got %d, wanted %d", tmpUtxo.Output.Amount(), testAmount)
t.Fatalf(
"did not get expected amount: got %d, wanted %d",
tmpUtxo.Output.Amount(),
testAmount,
)
}
}
12 changes: 9 additions & 3 deletions ledger/common/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,18 +181,24 @@ func (a *Address) populateFromBytes(data []byte) error {
}
payloadBytes, ok := rawAddr.Payload.Content.([]byte)
if !ok || rawAddr.Payload.Number != 24 {
return fmt.Errorf("invalid Byron address data: unexpected payload content")
return fmt.Errorf(
"invalid Byron address data: unexpected payload content",
)
}
payloadChecksum := crc32.ChecksumIEEE(payloadBytes)
if rawAddr.Checksum != payloadChecksum {
return fmt.Errorf("invalid Byron address data: checksum does not match")
return fmt.Errorf(
"invalid Byron address data: checksum does not match",
)
}
var byronAddr byronAddressPayload
if _, err := cbor.Decode(payloadBytes, &byronAddr); err != nil {
return err
}
if len(byronAddr.Hash) != AddressHashSize {
return fmt.Errorf("invalid Byron address data: hash is not expected length")
return fmt.Errorf(
"invalid Byron address data: hash is not expected length",
)
}
a.byronAddressType = byronAddr.AddrType
a.byronAddressAttr = byronAddr.Attr
Expand Down
16 changes: 13 additions & 3 deletions ledger/common/nonce.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,15 @@ func (n *Nonce) MarshalCBOR() ([]byte, error) {

// CalculateRollingNonce calculates a rolling nonce (eta_v) value from the previous block's eta_v value and the current
// block's VRF result
func CalculateRollingNonce(prevBlockNonce []byte, blockVrf []byte) (Blake2b256, error) {
func CalculateRollingNonce(
prevBlockNonce []byte,
blockVrf []byte,
) (Blake2b256, error) {
if len(blockVrf) != 32 && len(blockVrf) != 64 {
return Blake2b256{}, fmt.Errorf("invalid block VRF length: %d, expected 32 or 64", len(blockVrf))
return Blake2b256{}, fmt.Errorf(
"invalid block VRF length: %d, expected 32 or 64",
len(blockVrf),
)
}
blockVrfHash := Blake2b256Hash(blockVrf)
tmpData := slices.Concat(prevBlockNonce, blockVrfHash.Bytes())
Expand All @@ -96,7 +102,11 @@ func CalculateRollingNonce(prevBlockNonce []byte, blockVrf []byte) (Blake2b256,

// CalculateEpochNonce calculates an epoch nonce from the rolling nonce (eta_v) value of the block immediately before the stability
// window and the block hash of the first block from the previous epoch.
func CalculateEpochNonce(stableBlockNonce []byte, prevEpochFirstBlockHash []byte, extraEntropy []byte) (Blake2b256, error) {
func CalculateEpochNonce(
stableBlockNonce []byte,
prevEpochFirstBlockHash []byte,
extraEntropy []byte,
) (Blake2b256, error) {
tmpData := slices.Concat(
stableBlockNonce,
prevEpochFirstBlockHash,
Expand Down
22 changes: 18 additions & 4 deletions ledger/common/nonce_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,11 @@ func TestCalculateRollingNonce(t *testing.T) {
}
nonceHex := hex.EncodeToString(nonce.Bytes())
if nonceHex != testDef.expectedNonce {
t.Fatalf("did not get expected nonce value: got %s, wanted %s", nonceHex, testDef.expectedNonce)
t.Fatalf(
"did not get expected nonce value: got %s, wanted %s",
nonceHex,
testDef.expectedNonce,
)
}
rollingNonce = nonce.Bytes()
}
Expand Down Expand Up @@ -176,7 +180,9 @@ func TestCalculateEpochNonce(t *testing.T) {
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
prevEpochFirstBlockHash, err := hex.DecodeString(testDef.prevEpochFirstBlockHash)
prevEpochFirstBlockHash, err := hex.DecodeString(
testDef.prevEpochFirstBlockHash,
)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
Expand All @@ -188,13 +194,21 @@ func TestCalculateEpochNonce(t *testing.T) {
}
extraEntropy = tmpEntropy
}
tmpNonce, err := common.CalculateEpochNonce(stableBlockNonce, prevEpochFirstBlockHash, extraEntropy)
tmpNonce, err := common.CalculateEpochNonce(
stableBlockNonce,
prevEpochFirstBlockHash,
extraEntropy,
)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
tmpNonceHex := hex.EncodeToString(tmpNonce.Bytes())
if tmpNonceHex != testDef.expectedNonce {
t.Fatalf("did not get expected epoch nonce: got %s, wanted %s", tmpNonceHex, testDef.expectedNonce)
t.Fatalf(
"did not get expected epoch nonce: got %s, wanted %s",
tmpNonceHex,
testDef.expectedNonce,
)
}
}
}
4 changes: 3 additions & 1 deletion protocol/chainsync/chainsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,9 @@ func WithRollForwardFunc(rollForwardFunc RollForwardFunc) ChainSyncOptionFunc {
}

// WithRollForwardRawFunc specifies the RollForwardRaw callback function. This will provide the raw header or block
func WithRollForwardRawFunc(rollForwardRawFunc RollForwardRawFunc) ChainSyncOptionFunc {
func WithRollForwardRawFunc(
rollForwardRawFunc RollForwardRawFunc,
) ChainSyncOptionFunc {
return func(c *Config) {
c.RollForwardRawFunc = rollForwardRawFunc
}
Expand Down
4 changes: 3 additions & 1 deletion protocol/localstatequery/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ import "errors"
var ErrAcquireFailurePointTooOld = errors.New("acquire failure: point too old")

// ErrAcquireFailurePointNotOnChain indicates a failure to acquire a point due to it not being present on the chain
var ErrAcquireFailurePointNotOnChain = errors.New("acquire failure: point not on chain")
var ErrAcquireFailurePointNotOnChain = errors.New(
"acquire failure: point not on chain",
)
6 changes: 5 additions & 1 deletion protocol/localstatequery/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,11 @@ type ShelleyPoolDistrQuery struct {
simpleQueryBase
}

func decodeQuery(data []byte, typeDesc string, queryTypes map[int]any) (any, error) {
func decodeQuery(
data []byte,
typeDesc string,
queryTypes map[int]any,
) (any, error) {
// Determine query type
queryType, err := cbor.DecodeIdFromList(data)
if err != nil {
Expand Down
Loading