diff --git a/cbor/tags.go b/cbor/tags.go index 967d8027..5bf90bf8 100644 --- a/cbor/tags.go +++ b/cbor/tags.go @@ -42,7 +42,10 @@ var customTagSet _cbor.TagSet func init() { // Build custom tagset customTagSet = _cbor.NewTagSet() - tagOpts := _cbor.TagOptions{EncTag: _cbor.EncTagRequired, DecTag: _cbor.DecTagRequired} + tagOpts := _cbor.TagOptions{ + EncTag: _cbor.EncTagRequired, + DecTag: _cbor.DecTagRequired, + } // Wrapped CBOR if err := customTagSet.Add( tagOpts, diff --git a/cbor/value.go b/cbor/value.go index 98de7c0d..e1e0841e 100644 --- a/cbor/value.go +++ b/cbor/value.go @@ -290,7 +290,8 @@ func (c *Constructor) UnmarshalCBOR(data []byte) error { if _, err := Decode(tmpTag.Content, &tmpValue); err != nil { return err } - if tmpTag.Number >= CborTagAlternative1Min && tmpTag.Number <= CborTagAlternative1Max { + if tmpTag.Number >= CborTagAlternative1Min && + tmpTag.Number <= CborTagAlternative1Max { // Alternatives 0-6 c.constructor = uint(tmpTag.Number - CborTagAlternative1Min) c.value = &tmpValue diff --git a/cbor/value_test.go b/cbor/value_test.go index af5e78bf..4151f100 100644 --- a/cbor/value_test.go +++ b/cbor/value_test.go @@ -336,7 +336,10 @@ func TestConstructorDecode(t *testing.T) { testDef.expectedObj.Constructor(), ) } - if !reflect.DeepEqual(tmpConstr.Fields(), testDef.expectedObj.Fields()) { + if !reflect.DeepEqual( + tmpConstr.Fields(), + testDef.expectedObj.Fields(), + ) { t.Fatalf( "did not decode to expected fields\n got: %#v\n wanted: %#v", tmpConstr.Fields(), diff --git a/cmd/gouroboros/chainsync.go b/cmd/gouroboros/chainsync.go index 50a9fd38..cb0d44fe 100644 --- a/cmd/gouroboros/chainsync.go +++ b/cmd/gouroboros/chainsync.go @@ -261,7 +261,11 @@ func testChainSync(f *globalFlags) { select {} } -func chainSyncRollBackwardHandler(ctx chainsync.CallbackContext, point common.Point, tip chainsync.Tip) error { +func chainSyncRollBackwardHandler( + ctx chainsync.CallbackContext, + point common.Point, + tip chainsync.Tip, +) error { fmt.Printf("roll backward: point = %#v, tip = %#v\n", point, tip) return nil } @@ -318,7 +322,10 @@ func chainSyncRollForwardHandler( return nil } -func blockFetchBlockHandler(ctx blockfetch.CallbackContext, blockData ledger.Block) error { +func blockFetchBlockHandler( + ctx blockfetch.CallbackContext, + blockData ledger.Block, +) error { switch block := blockData.(type) { case *ledger.ByronEpochBoundaryBlock: fmt.Printf("era = Byron (EBB), epoch = %d, slot = %d, id = %s\n", block.Header.ConsensusData.Epoch, block.SlotNumber(), block.Hash()) diff --git a/cmd/gouroboros/query.go b/cmd/gouroboros/query.go index fda1980b..e61c3b01 100644 --- a/cmd/gouroboros/query.go +++ b/cmd/gouroboros/query.go @@ -191,7 +191,9 @@ func testQuery(f *globalFlags) { } tmpPools = append(tmpPools, tmpPoolId) } - poolParams, err := o.LocalStateQuery().Client.GetStakePoolParams(tmpPools) + poolParams, err := o.LocalStateQuery().Client.GetStakePoolParams( + tmpPools, + ) if err != nil { fmt.Printf("ERROR: failure querying stake pool params: %s\n", err) os.Exit(1) diff --git a/cmd/tx-submission/main.go b/cmd/tx-submission/main.go index 76e20542..f0114d43 100644 --- a/cmd/tx-submission/main.go +++ b/cmd/tx-submission/main.go @@ -118,7 +118,10 @@ func main() { // convert to tx txType, err := ledger.DetermineTransactionType(txBytes) if err != nil { - fmt.Printf("ERROR: could not parse transaction to determine type: %s", err) + fmt.Printf( + "ERROR: could not parse transaction to determine type: %s", + err, + ) os.Exit(1) } tx, err := ledger.NewTransactionFromCbor(txType, txBytes) diff --git a/connection.go b/connection.go index 44d172a6..0287ffa6 100644 --- a/connection.go +++ b/connection.go @@ -146,7 +146,11 @@ func (c *Connection) Dial(proto string, address string) error { // passed to the [net.DialTimeout] func. The handshake will be started when a connection is established. // An error will be returned if the connection fails, a connection was already established, or the // handshake fails -func (c *Connection) DialTimeout(proto string, address string, timeout time.Duration) error { +func (c *Connection) DialTimeout( + proto string, + address string, + timeout time.Duration, +) error { if c.conn != nil { return fmt.Errorf("a connection was already established") } @@ -310,17 +314,19 @@ func (c *Connection) setupConnection() error { var handshakeFullDuplex bool handshakeConfig := handshake.NewConfig( handshake.WithProtocolVersionMap(protoVersions), - handshake.WithFinishedFunc(func(ctx handshake.CallbackContext, version uint16, versionData protocol.VersionData) error { - c.handshakeVersion = version - c.handshakeVersionData = versionData - if c.useNodeToNodeProto { - if versionData.DiffusionMode() == protocol.DiffusionModeInitiatorAndResponder { - handshakeFullDuplex = true + handshake.WithFinishedFunc( + func(ctx handshake.CallbackContext, version uint16, versionData protocol.VersionData) error { + c.handshakeVersion = version + c.handshakeVersionData = versionData + if c.useNodeToNodeProto { + if versionData.DiffusionMode() == protocol.DiffusionModeInitiatorAndResponder { + handshakeFullDuplex = true + } } - } - close(c.handshakeFinishedChan) - return nil - }), + close(c.handshakeFinishedChan) + return nil + }, + ), ) c.handshake = handshake.New(protoOptions, &handshakeConfig) if c.server { diff --git a/connection_manager.go b/connection_manager.go index e5fe43dc..b7951922 100644 --- a/connection_manager.go +++ b/connection_manager.go @@ -78,7 +78,11 @@ func NewConnectionManager(cfg ConnectionManagerConfig) *ConnectionManager { } } -func (c *ConnectionManager) AddHost(address string, port uint, tags ...ConnectionManagerTag) { +func (c *ConnectionManager) AddHost( + address string, + port uint, + tags ...ConnectionManagerTag, +) { tmpTags := map[ConnectionManagerTag]bool{} for _, tag := range tags { tmpTags[tag] = true @@ -99,12 +103,20 @@ func (c *ConnectionManager) AddHostsFromTopology(topology *TopologyConfig) { } for _, localRoot := range topology.LocalRoots { for _, host := range localRoot.AccessPoints { - c.AddHost(host.Address, host.Port, ConnectionManagerTagHostLocalRoot) + c.AddHost( + host.Address, + host.Port, + ConnectionManagerTagHostLocalRoot, + ) } } for _, publicRoot := range topology.PublicRoots { for _, host := range publicRoot.AccessPoints { - c.AddHost(host.Address, host.Port, ConnectionManagerTagHostPublicRoot) + c.AddHost( + host.Address, + host.Port, + ConnectionManagerTagHostPublicRoot, + ) } } } @@ -129,13 +141,17 @@ func (c *ConnectionManager) RemoveConnection(connId ConnectionId) { c.connectionsMutex.Unlock() } -func (c *ConnectionManager) GetConnectionById(connId ConnectionId) *ConnectionManagerConnection { +func (c *ConnectionManager) GetConnectionById( + connId ConnectionId, +) *ConnectionManagerConnection { c.connectionsMutex.Lock() defer c.connectionsMutex.Unlock() return c.connections[connId] } -func (c *ConnectionManager) GetConnectionsByTags(tags ...ConnectionManagerTag) []*ConnectionManagerConnection { +func (c *ConnectionManager) GetConnectionsByTags( + tags ...ConnectionManagerTag, +) []*ConnectionManagerConnection { var ret []*ConnectionManagerConnection c.connectionsMutex.Lock() for _, conn := range c.connections { diff --git a/connection_manager_test.go b/connection_manager_test.go index 71619ceb..0b96b543 100644 --- a/connection_manager_test.go +++ b/connection_manager_test.go @@ -56,10 +56,18 @@ func TestConnectionManagerConnError(t *testing.T) { ConnClosedFunc: func(connId ouroboros.ConnectionId, err error) { if err != nil { if connId != expectedConnId { - t.Fatalf("did not receive error from expected connection: got %d, wanted %d", connId, expectedConnId) + t.Fatalf( + "did not receive error from expected connection: got %d, wanted %d", + connId, + expectedConnId, + ) } if err != expectedErr { - t.Fatalf("did not receive expected error: got: %s, expected: %s", err, expectedErr) + t.Fatalf( + "did not receive expected error: got: %s, expected: %s", + err, + expectedErr, + ) } close(doneChan) } @@ -121,7 +129,11 @@ func TestConnectionManagerConnClosed(t *testing.T) { ouroboros.ConnectionManagerConfig{ ConnClosedFunc: func(connId ouroboros.ConnectionId, err error) { if connId != expectedConnId { - t.Fatalf("did not receive closed signal from expected connection: got %d, wanted %d", connId, expectedConnId) + t.Fatalf( + "did not receive closed signal from expected connection: got %d, wanted %d", + connId, + expectedConnId, + ) } if err != nil { t.Fatalf("received unexpected error: %s", err) diff --git a/ledger/alonzo.go b/ledger/alonzo.go index 89810e48..90deecaa 100644 --- a/ledger/alonzo.go +++ b/ledger/alonzo.go @@ -452,10 +452,15 @@ func NewAlonzoTransactionFromCbor(data []byte) (*AlonzoTransaction, error) { return &alonzoTx, nil } -func NewAlonzoTransactionOutputFromCbor(data []byte) (*AlonzoTransactionOutput, error) { +func NewAlonzoTransactionOutputFromCbor( + data []byte, +) (*AlonzoTransactionOutput, error) { var alonzoTxOutput AlonzoTransactionOutput if _, err := cbor.Decode(data, &alonzoTxOutput); err != nil { - return nil, fmt.Errorf("Alonzo transaction output decode error: %s", err) + return nil, fmt.Errorf( + "Alonzo transaction output decode error: %s", + err, + ) } return &alonzoTxOutput, nil } diff --git a/ledger/babbage.go b/ledger/babbage.go index 773e0441..26781d19 100644 --- a/ledger/babbage.go +++ b/ledger/babbage.go @@ -649,10 +649,15 @@ func NewBabbageTransactionFromCbor(data []byte) (*BabbageTransaction, error) { return &babbageTx, nil } -func NewBabbageTransactionOutputFromCbor(data []byte) (*BabbageTransactionOutput, error) { +func NewBabbageTransactionOutputFromCbor( + data []byte, +) (*BabbageTransactionOutput, error) { var babbageTxOutput BabbageTransactionOutput if _, err := cbor.Decode(data, &babbageTxOutput); err != nil { - return nil, fmt.Errorf("Babbage transaction output decode error: %s", err) + return nil, fmt.Errorf( + "Babbage transaction output decode error: %s", + err, + ) } return &babbageTxOutput, nil } diff --git a/ledger/babbage_test.go b/ledger/babbage_test.go index f0817421..64efb797 100644 --- a/ledger/babbage_test.go +++ b/ledger/babbage_test.go @@ -9,7 +9,10 @@ func TestBabbageBlockTransactions(t *testing.T) { t.Run("empty", func(t *testing.T) { if lenTxs := len(b.Transactions()); lenTxs != 0 { - t.Fatalf("expected number of transactions is 0 but it was %d", lenTxs) + t.Fatalf( + "expected number of transactions is 0 but it was %d", + lenTxs, + ) } }) @@ -36,12 +39,21 @@ func TestBabbageBlockTransactions(t *testing.T) { txs := b.Transactions() if lenTxs := len(txs); lenTxs != txsCount { - t.Fatalf("expected number of transactions is %d but it was %d", txsCount, lenTxs) + t.Fatalf( + "expected number of transactions is %d but it was %d", + txsCount, + lenTxs, + ) } for i, tx := range txs { if btx := tx.(*BabbageTransaction); !btx.IsValid() { - t.Fatalf("expected transaction number %d IsValid is %v but is was %v", i, true, btx.IsValid()) + t.Fatalf( + "expected transaction number %d IsValid is %v but is was %v", + i, + true, + btx.IsValid(), + ) } } }) @@ -51,13 +63,22 @@ func TestBabbageBlockTransactions(t *testing.T) { txs := b.Transactions() if lenTxs := len(txs); lenTxs != txsCount { - t.Fatalf("expected number of transactions is %d but it was %d", txsCount, lenTxs) + t.Fatalf( + "expected number of transactions is %d but it was %d", + txsCount, + lenTxs, + ) } for i, tx := range txs { expected := i != 2 && i != 4 && i != 5 if btx := tx.(*BabbageTransaction); btx.IsValid() != expected { - t.Fatalf("expected transaction number %d IsValid is %v but is was %v", i, expected, btx.IsValid()) + t.Fatalf( + "expected transaction number %d IsValid is %v but is was %v", + i, + expected, + btx.IsValid(), + ) } } }) diff --git a/ledger/block.go b/ledger/block.go index 442b717b..9d0621c2 100644 --- a/ledger/block.go +++ b/ledger/block.go @@ -108,7 +108,10 @@ func generateBlockHeaderHash(data []byte, prefix []byte) string { tmpHash, err := blake2b.New256(nil) if err != nil { panic( - fmt.Sprintf("unexpected error generating empty blake2b hash: %s", err), + fmt.Sprintf( + "unexpected error generating empty blake2b hash: %s", + err, + ), ) } if prefix != nil { diff --git a/ledger/certs.go b/ledger/certs.go index 7095b618..0cf972b9 100644 --- a/ledger/certs.go +++ b/ledger/certs.go @@ -389,7 +389,9 @@ type MoveInstantaneousRewardsCertificateReward struct { OtherPot uint64 } -func (r *MoveInstantaneousRewardsCertificateReward) UnmarshalCBOR(data []byte) error { +func (r *MoveInstantaneousRewardsCertificateReward) UnmarshalCBOR( + data []byte, +) error { // Try to parse as map tmpMapData := struct { cbor.StructAsArray @@ -424,7 +426,9 @@ type MoveInstantaneousRewardsCertificate struct { func (c MoveInstantaneousRewardsCertificate) isCertificate() {} -func (c *MoveInstantaneousRewardsCertificate) UnmarshalCBOR(cborData []byte) error { +func (c *MoveInstantaneousRewardsCertificate) UnmarshalCBOR( + cborData []byte, +) error { return c.UnmarshalCbor(cborData, c) } diff --git a/ledger/common.go b/ledger/common.go index 99b210bc..7a539230 100644 --- a/ledger/common.go +++ b/ledger/common.go @@ -164,7 +164,10 @@ func (a AssetFingerprint) Hash() Blake2b160 { tmpHash, err := blake2b.New(20, nil) if err != nil { panic( - fmt.Sprintf("unexpected error creating empty blake2b hash: %s", err), + fmt.Sprintf( + "unexpected error creating empty blake2b hash: %s", + err, + ), ) } tmpHash.Write(a.policyId) @@ -276,10 +279,16 @@ func NewAddressFromParts( stakingAddr []byte, ) (Address, error) { if len(paymentAddr) != AddressHashSize { - return Address{}, fmt.Errorf("invalid payment address hash length: %d", len(paymentAddr)) + return Address{}, fmt.Errorf( + "invalid payment address hash length: %d", + len(paymentAddr), + ) } if len(stakingAddr) > 0 && len(stakingAddr) != AddressHashSize { - return Address{}, fmt.Errorf("invalid staking address hash length: %d", len(stakingAddr)) + return Address{}, fmt.Errorf( + "invalid staking address hash length: %d", + len(stakingAddr), + ) } return Address{ addressType: addrType, @@ -305,7 +314,8 @@ func (a *Address) populateFromBytes(data []byte) error { return fmt.Errorf("invalid address length: %d", dataLen) } // Check bounds of second part if the address type is supposed to have one - if a.addressType != AddressTypeKeyNone && a.addressType != AddressTypeScriptNone { + if a.addressType != AddressTypeKeyNone && + a.addressType != AddressTypeScriptNone { if dataLen > (AddressHashSize + 1) { if dataLen < (AddressHashSize + AddressHashSize + 1) { return fmt.Errorf("invalid address length: %d", dataLen) @@ -318,7 +328,8 @@ func (a *Address) populateFromBytes(data []byte) error { payload := data[1:] a.paymentAddress = payload[:AddressHashSize] payload = payload[AddressHashSize:] - if a.addressType != AddressTypeKeyNone && a.addressType != AddressTypeScriptNone { + if a.addressType != AddressTypeKeyNone && + a.addressType != AddressTypeScriptNone { if len(payload) >= AddressHashSize { a.stakingAddress = payload[:AddressHashSize] payload = payload[AddressHashSize:] @@ -465,7 +476,10 @@ func (i IssuerVkey) Hash() Blake2b224 { hash, err := blake2b.New(28, nil) if err != nil { panic( - fmt.Sprintf("unexpected error creating empty blake2b hash: %s", err), + fmt.Sprintf( + "unexpected error creating empty blake2b hash: %s", + err, + ), ) } hash.Write(i[:]) diff --git a/ledger/common_test.go b/ledger/common_test.go index 54454666..a7cc5fd9 100644 --- a/ledger/common_test.go +++ b/ledger/common_test.go @@ -152,7 +152,9 @@ func TestAddressFromBytes(t *testing.T) { } for _, testDef := range testDefs { addr := Address{} - err := addr.populateFromBytes(test.DecodeHexString(testDef.addressBytesHex)) + err := addr.populateFromBytes( + test.DecodeHexString(testDef.addressBytesHex), + ) if err != nil { t.Fatalf( "failure populating address from bytes: %s", diff --git a/ledger/mary.go b/ledger/mary.go index 974dcfc1..4f698d30 100644 --- a/ledger/mary.go +++ b/ledger/mary.go @@ -386,7 +386,9 @@ func NewMaryTransactionFromCbor(data []byte) (*MaryTransaction, error) { return &maryTx, nil } -func NewMaryTransactionOutputFromCbor(data []byte) (*MaryTransactionOutput, error) { +func NewMaryTransactionOutputFromCbor( + data []byte, +) (*MaryTransactionOutput, error) { var maryTxOutput MaryTransactionOutput if _, err := cbor.Decode(data, &maryTxOutput); err != nil { return nil, fmt.Errorf("Mary transaction output decode error: %s", err) diff --git a/ledger/shelley.go b/ledger/shelley.go index 39b3cb38..dce841e9 100644 --- a/ledger/shelley.go +++ b/ledger/shelley.go @@ -629,10 +629,15 @@ func NewShelleyTransactionFromCbor(data []byte) (*ShelleyTransaction, error) { return &shelleyTx, nil } -func NewShelleyTransactionOutputFromCbor(data []byte) (*ShelleyTransactionOutput, error) { +func NewShelleyTransactionOutputFromCbor( + data []byte, +) (*ShelleyTransactionOutput, error) { var shelleyTxOutput ShelleyTransactionOutput if _, err := cbor.Decode(data, &shelleyTxOutput); err != nil { - return nil, fmt.Errorf("Shelley transaction output decode error: %s", err) + return nil, fmt.Errorf( + "Shelley transaction output decode error: %s", + err, + ) } return &shelleyTxOutput, nil } diff --git a/ledger/tx.go b/ledger/tx.go index cdf55e88..25f8bbc2 100644 --- a/ledger/tx.go +++ b/ledger/tx.go @@ -167,7 +167,10 @@ func generateTransactionHash(data []byte, prefix []byte) string { tmpHash, err := blake2b.New256(nil) if err != nil { panic( - fmt.Sprintf("unexpected error generating empty blake2b hash: %s", err), + fmt.Sprintf( + "unexpected error generating empty blake2b hash: %s", + err, + ), ) } if prefix != nil { diff --git a/ledger/verify_block.go b/ledger/verify_block.go index dc6fdf45..dd8c421e 100644 --- a/ledger/verify_block.go +++ b/ledger/verify_block.go @@ -38,22 +38,36 @@ func VerifyBlock(block BlockHexCbor) (error, bool, string, uint64, uint64) { // check is KES valid headerCborByte, headerDecodeError := hex.DecodeString(headerCborHex) if headerDecodeError != nil { - return fmt.Errorf("VerifyBlock: headerCborByte decode error, %v", headerDecodeError.Error()), false, "", 0, 0 + return fmt.Errorf( + "VerifyBlock: headerCborByte decode error, %v", + headerDecodeError.Error(), + ), false, "", 0, 0 } - header, headerUnmarshalError := NewBabbageBlockHeaderFromCbor(headerCborByte) + header, headerUnmarshalError := NewBabbageBlockHeaderFromCbor( + headerCborByte, + ) if headerUnmarshalError != nil { - return fmt.Errorf("VerifyBlock: header unmarshal error, %v", headerUnmarshalError.Error()), false, "", 0, 0 + return fmt.Errorf( + "VerifyBlock: header unmarshal error, %v", + headerUnmarshalError.Error(), + ), false, "", 0, 0 } isKesValid, errKes := VerifyKes(header, slotPerKesPeriod) if errKes != nil { - return fmt.Errorf("VerifyBlock: KES invalid, %v", errKes.Error()), false, "", 0, 0 + return fmt.Errorf( + "VerifyBlock: KES invalid, %v", + errKes.Error(), + ), false, "", 0, 0 } // check is VRF valid // Ref: https://github.com/IntersectMBO/ouroboros-consensus/blob/de74882102236fdc4dd25aaa2552e8b3e208448c/ouroboros-consensus-protocol/src/ouroboros-consensus-protocol/Ouroboros/Consensus/Protocol/Praos.hs#L541 epochNonceByte, epochNonceDecodeError := hex.DecodeString(epochNonceHex) if epochNonceDecodeError != nil { - return fmt.Errorf("VerifyBlock: epochNonceByte decode error, %v", epochNonceDecodeError.Error()), false, "", 0, 0 + return fmt.Errorf( + "VerifyBlock: epochNonceByte decode error, %v", + epochNonceDecodeError.Error(), + ), false, "", 0, 0 } vrfBytes := header.Body.VrfKey[:] vrfResult := header.Body.VrfResult.([]interface{}) @@ -62,7 +76,10 @@ func VerifyBlock(block BlockHexCbor) (error, bool, string, uint64, uint64) { seed := MkInputVrf(int64(header.Body.Slot), epochNonceByte) output, errVrf := VrfVerifyAndHash(vrfBytes, vrfProofBytes, seed) if errVrf != nil { - return fmt.Errorf("VerifyBlock: vrf invalid, %v", errVrf.Error()), false, "", 0, 0 + return fmt.Errorf( + "VerifyBlock: vrf invalid, %v", + errVrf.Error(), + ), false, "", 0, 0 } isVrfValid := bytes.Equal(output, vrfOutputBytes) @@ -71,7 +88,10 @@ func VerifyBlock(block BlockHexCbor) (error, bool, string, uint64, uint64) { blockBodyHashHex := hex.EncodeToString(blockBodyHash[:]) isBodyValid, isBodyValidError := VerifyBlockBody(bodyHex, blockBodyHashHex) if isBodyValidError != nil { - return fmt.Errorf("VerifyBlock: VerifyBlockBody error, %v", isBodyValidError.Error()), false, "", 0, 0 + return fmt.Errorf( + "VerifyBlock: VerifyBlockBody error, %v", + isBodyValidError.Error(), + ), false, "", 0, 0 } isValid = isKesValid && isVrfValid && isBodyValid vrfHex = hex.EncodeToString(vrfBytes) @@ -80,23 +100,39 @@ func VerifyBlock(block BlockHexCbor) (error, bool, string, uint64, uint64) { return nil, isValid, vrfHex, blockNo, slotNo } -func ExtractBlockData(bodyHex string) ([]UTXOOutput, []RegisCert, []DeRegisCert, error) { +func ExtractBlockData( + bodyHex string, +) ([]UTXOOutput, []RegisCert, []DeRegisCert, error) { rawDataBytes, rawDataBytesError := hex.DecodeString(bodyHex) if rawDataBytesError != nil { - return nil, nil, nil, fmt.Errorf("ExtractBlockData: bodyHex decode error, %v", rawDataBytesError.Error()) + return nil, nil, nil, fmt.Errorf( + "ExtractBlockData: bodyHex decode error, %v", + rawDataBytesError.Error(), + ) } var txsRaw [][]string _, err := cbor.Decode(rawDataBytes, &txsRaw) if err != nil { - return nil, nil, nil, fmt.Errorf("ExtractBlockData: txsRaw decode error, %v", err.Error()) + return nil, nil, nil, fmt.Errorf( + "ExtractBlockData: txsRaw decode error, %v", + err.Error(), + ) } txBodies, txBodiesError := GetTxBodies(txsRaw) if err != nil { - return nil, nil, nil, fmt.Errorf("ExtractBlockData: GetTxBodies error, %v", txBodiesError.Error()) + return nil, nil, nil, fmt.Errorf( + "ExtractBlockData: GetTxBodies error, %v", + txBodiesError.Error(), + ) } - uTXOOutput, regisCerts, deRegisCerts, getBlockOutputError := GetBlockOutput(txBodies) + uTXOOutput, regisCerts, deRegisCerts, getBlockOutputError := GetBlockOutput( + txBodies, + ) if getBlockOutputError != nil { - return nil, nil, nil, fmt.Errorf("ExtractBlockData: GetBlockOutput error, %v", getBlockOutputError.Error()) + return nil, nil, nil, fmt.Errorf( + "ExtractBlockData: GetBlockOutput error, %v", + getBlockOutputError.Error(), + ) } return uTXOOutput, regisCerts, deRegisCerts, nil } diff --git a/ledger/verify_block_body.go b/ledger/verify_block_body.go index ac8b6e8b..dd184949 100644 --- a/ledger/verify_block_body.go +++ b/ledger/verify_block_body.go @@ -40,19 +40,30 @@ func VerifyBlockBody(data string, blockBodyHash string) (bool, error) { var txsRaw [][]string _, err := cbor.Decode(rawDataBytes, &txsRaw) if err != nil { - return false, fmt.Errorf("VerifyBlockBody: txs decode error, %v", err.Error()) + return false, fmt.Errorf( + "VerifyBlockBody: txs decode error, %v", + err.Error(), + ) } blockBodyHashByte, decodeBBHError := hex.DecodeString(blockBodyHash) if decodeBBHError != nil { - return false, fmt.Errorf("VerifyBlockBody: blockBodyHashByte decode error, %v", decodeBBHError.Error()) + return false, fmt.Errorf( + "VerifyBlockBody: blockBodyHashByte decode error, %v", + decodeBBHError.Error(), + ) } var calculateBlockBodyHashByte [32]byte if len(txsRaw) == 0 { - zeroTxHash, decodeZTHError := hex.DecodeString(BLOCK_BODY_HASH_ZERO_TX_HEX) + zeroTxHash, decodeZTHError := hex.DecodeString( + BLOCK_BODY_HASH_ZERO_TX_HEX, + ) if decodeZTHError != nil { - return false, fmt.Errorf("VerifyBlockBody: zeroTxHash decode error, %v", decodeZTHError.Error()) + return false, fmt.Errorf( + "VerifyBlockBody: zeroTxHash decode error, %v", + decodeZTHError.Error(), + ) } copy(calculateBlockBodyHashByte[:], zeroTxHash[:32]) } else { @@ -72,19 +83,31 @@ func CalculateBlockBodyHash(txsRaw [][]string) ([]byte, error) { txSeqNonValid := []uint{} for index, tx := range txsRaw { if len(tx) != 3 { - return nil, fmt.Errorf("CalculateBlockBodyHash: tx len error, tx index %v length = %v", index, len(tx)) + return nil, fmt.Errorf( + "CalculateBlockBodyHash: tx len error, tx index %v length = %v", + index, + len(tx), + ) } bodyTmpHex := tx[0] bodyTmpBytes, bodyTmpBytesError := hex.DecodeString(bodyTmpHex) if bodyTmpBytesError != nil { - return nil, fmt.Errorf("CalculateBlockBodyHash: decode body tx[%v] error, %v", index, bodyTmpBytesError.Error()) + return nil, fmt.Errorf( + "CalculateBlockBodyHash: decode body tx[%v] error, %v", + index, + bodyTmpBytesError.Error(), + ) } txSeqBody = append(txSeqBody, bodyTmpBytes) witTmpHex := tx[1] witTmpBytes, witTmpBytesError := hex.DecodeString(witTmpHex) if witTmpBytesError != nil { - return nil, fmt.Errorf("CalculateBlockBodyHash: decode wit tx[%v] error, %v", index, witTmpBytesError.Error()) + return nil, fmt.Errorf( + "CalculateBlockBodyHash: decode wit tx[%v] error, %v", + index, + witTmpBytesError.Error(), + ) } txSeqWit = append(txSeqWit, witTmpBytes) @@ -93,7 +116,11 @@ func CalculateBlockBodyHash(txsRaw [][]string) ([]byte, error) { if auxTmpHex != "" { auxBytes, auxBytesError := hex.DecodeString(auxTmpHex) if auxBytesError != nil { - return nil, fmt.Errorf("CalculateBlockBodyHash: decode aux tx[%v] error, %v", index, auxBytesError.Error()) + return nil, fmt.Errorf( + "CalculateBlockBodyHash: decode aux tx[%v] error, %v", + index, + auxBytesError.Error(), + ) } // Cardano use Tag 259 for this when encCbor // Ref: https://github.com/IntersectMBO/cardano-ledger/blob/master/eras/alonzo/impl/src/Cardano/Ledger/Alonzo/TxAuxData.hs#L125 @@ -105,7 +132,10 @@ func CalculateBlockBodyHash(txsRaw [][]string) ([]byte, error) { } txSeqBodyBytes, txSeqBodyBytesError := cbor.Encode(txSeqBody) if txSeqBodyBytesError != nil { - return nil, fmt.Errorf("CalculateBlockBodyHash: encode txSeqBody error, %v", txSeqBodyBytesError.Error()) + return nil, fmt.Errorf( + "CalculateBlockBodyHash: encode txSeqBody error, %v", + txSeqBodyBytesError.Error(), + ) } txSeqBodySum32Bytes := blake2b.Sum256(txSeqBodyBytes) @@ -113,21 +143,30 @@ func CalculateBlockBodyHash(txsRaw [][]string) ([]byte, error) { txSeqWitsBytes, txSeqWitsBytesError := cbor.Encode(txSeqWit) if txSeqWitsBytesError != nil { - return nil, fmt.Errorf("CalculateBlockBodyHash: encode txSeqWit error, %v", txSeqWitsBytesError.Error()) + return nil, fmt.Errorf( + "CalculateBlockBodyHash: encode txSeqWit error, %v", + txSeqWitsBytesError.Error(), + ) } txSeqWitsSum32Bytes := blake2b.Sum256(txSeqWitsBytes) txSeqWitsSumBytes := txSeqWitsSum32Bytes[:] txSeqMetadataBytes, txSeqMetadataBytesError := cbor.Encode(txSeqMetadata) if txSeqMetadataBytesError != nil { - return nil, fmt.Errorf("CalculateBlockBodyHash: encode txSeqMetadata error, %v", txSeqMetadataBytesError.Error()) + return nil, fmt.Errorf( + "CalculateBlockBodyHash: encode txSeqMetadata error, %v", + txSeqMetadataBytesError.Error(), + ) } txSeqMetadataSum32Bytes := blake2b.Sum256(txSeqMetadataBytes) txSeqMetadataSumBytes := txSeqMetadataSum32Bytes[:] txSeqNonValidBytes, txSeqNonValidBytesError := cbor.Encode(txSeqNonValid) if txSeqNonValidBytesError != nil { - return nil, fmt.Errorf("CalculateBlockBodyHash: encode txSeqNonValid error, %v", txSeqNonValidBytesError.Error()) + return nil, fmt.Errorf( + "CalculateBlockBodyHash: encode txSeqNonValid error, %v", + txSeqNonValidBytesError.Error(), + ) } txSeqIsValidSum32Bytes := blake2b.Sum256(txSeqNonValidBytes) txSeqIsValidSumBytes := txSeqIsValidSum32Bytes[:] @@ -149,18 +188,28 @@ func GetTxBodies(txsRaw [][]string) ([]BabbageTransactionBody, error) { bodyTmpHex := tx[0] bodyTmpBytes, bodyTmpBytesError := hex.DecodeString(bodyTmpHex) if bodyTmpBytesError != nil { - return nil, fmt.Errorf("CalculateBlockBodyHash: decode bodyTmpBytesError, index %v, error, %v", index, bodyTmpBytesError.Error()) + return nil, fmt.Errorf( + "CalculateBlockBodyHash: decode bodyTmpBytesError, index %v, error, %v", + index, + bodyTmpBytesError.Error(), + ) } _, err := cbor.Decode(bodyTmpBytes, &tmp) if err != nil { - return nil, fmt.Errorf("CalculateBlockBodyHash: decode bodyTmpBytes, index %v, error, %v", index, err.Error()) + return nil, fmt.Errorf( + "CalculateBlockBodyHash: decode bodyTmpBytes, index %v, error, %v", + index, + err.Error(), + ) } bodies = append(bodies, tmp) } return bodies, nil } -func GetBlockOutput(txBodies []BabbageTransactionBody) ([]UTXOOutput, []RegisCert, []DeRegisCert, error) { +func GetBlockOutput( + txBodies []BabbageTransactionBody, +) ([]UTXOOutput, []RegisCert, []DeRegisCert, error) { var outputs []UTXOOutput var regisCerts []RegisCert var deRegisCerts []DeRegisCert @@ -175,7 +224,12 @@ func GetBlockOutput(txBodies []BabbageTransactionBody) ([]UTXOOutput, []RegisCer cborDatumHex := hex.EncodeToString(cborDatum) tokens, extractTokensError := ExtractTokens(txOutput) if extractTokensError != nil { - return nil, nil, nil, fmt.Errorf("GetBlockOutput: ExtractTokens error, tx index %v, outputIndex %v, error, %v", txIndex, outputIndex, extractTokensError.Error()) + return nil, nil, nil, fmt.Errorf( + "GetBlockOutput: ExtractTokens error, tx index %v, outputIndex %v, error, %v", + txIndex, + outputIndex, + extractTokensError.Error(), + ) } tmpOutput := UTXOOutput{ TxHash: txHash, @@ -230,7 +284,10 @@ func GetBlockOutput(txBodies []BabbageTransactionBody) ([]UTXOOutput, []RegisCer func PoolIdToBech32(data []byte) (string, error) { pool, err := bech32.ConvertAndEncode("pool", data) if err != nil { - return "", fmt.Errorf("PoolIdToBech32: ConvertAndEncode error, %v", err.Error()) + return "", fmt.Errorf( + "PoolIdToBech32: ConvertAndEncode error, %v", + err.Error(), + ) } return pool, nil } @@ -245,12 +302,18 @@ func ExtractTokens(output TransactionOutput) ([]UTXOOutputToken, error) { if output.Assets() != nil { assetsBytes, assetsBytesError := output.Assets().MarshalJSON() if assetsBytesError != nil { - return nil, fmt.Errorf("ExtractTokens: MarshalJSON assets error, %v", assetsBytesError.Error()) + return nil, fmt.Errorf( + "ExtractTokens: MarshalJSON assets error, %v", + assetsBytesError.Error(), + ) } var assets []multiAssetJson[MultiAssetTypeOutput] err := json.Unmarshal(assetsBytes, &assets) if err != nil { - return nil, fmt.Errorf("ExtractTokens: json.Unmarshal error, %v", err.Error()) + return nil, fmt.Errorf( + "ExtractTokens: json.Unmarshal error, %v", + err.Error(), + ) } for _, asset := range assets { outputTokens = append(outputTokens, UTXOOutputToken{ @@ -297,21 +360,21 @@ type DeRegisCert struct { } func GetListRegisCertPoolId(regisCerts []RegisCert) []string { - poolId := make([]string, 0) - if len(regisCerts) > 0 { - for _, cert := range regisCerts { - poolId = append(poolId, cert.RegisPoolId) - } - } - return poolId + poolId := make([]string, 0) + if len(regisCerts) > 0 { + for _, cert := range regisCerts { + poolId = append(poolId, cert.RegisPoolId) + } + } + return poolId } func GetListUnregisCertPoolId(deRegisCerts []DeRegisCert) []string { - poolId := make([]string, 0) - if len(deRegisCerts) > 0 { - for _, cert := range deRegisCerts { - poolId = append(poolId, cert.DeRegisPoolId) - } - } - return poolId + poolId := make([]string, 0) + if len(deRegisCerts) > 0 { + for _, cert := range deRegisCerts { + poolId = append(poolId, cert.DeRegisPoolId) + } + } + return poolId } diff --git a/ledger/verify_kes.go b/ledger/verify_kes.go index 63194a89..50592c64 100644 --- a/ledger/verify_kes.go +++ b/ledger/verify_kes.go @@ -65,7 +65,11 @@ func NewSumKesFromByte(depth uint64, fromByte []byte) SumXKesSig { } } -func (s SumXKesSig) Verify(period uint64, pubKey ed25519.PublicKey, msg []byte) bool { +func (s SumXKesSig) Verify( + period uint64, + pubKey ed25519.PublicKey, + msg []byte, +) bool { pk2 := HashPair(s.LeftHandSidePublicKey, s.RightHandSidePublicKey) if !bytes.Equal(pk2, pubKey) { return false @@ -94,7 +98,10 @@ func HashPair(l ed25519.PublicKey, r ed25519.PublicKey) ed25519.PublicKey { h, err := blake2b.New(32, nil) if err != nil { panic( - fmt.Sprintf("unexpected error creating empty blake2b hash: %s", err), + fmt.Sprintf( + "unexpected error creating empty blake2b hash: %s", + err, + ), ) } h.Write(l[:]) @@ -108,12 +115,19 @@ func Sum0KesSigFromByte(sigBytes []byte) Sum0KesSig { type Sum0KesSig []byte -func (s Sum0KesSig) Verify(_ uint64, pubKey ed25519.PublicKey, msg []byte) bool { +func (s Sum0KesSig) Verify( + _ uint64, + pubKey ed25519.PublicKey, + msg []byte, +) bool { return ed25519.Verify(pubKey, msg, s) } // TODO: make this work on anything from Shelley onward -func VerifyKes(header *BabbageBlockHeader, slotsPerKesPeriod uint64) (bool, error) { +func VerifyKes( + header *BabbageBlockHeader, + slotsPerKesPeriod uint64, +) (bool, error) { // Ref: https://github.com/IntersectMBO/ouroboros-consensus/blob/de74882102236fdc4dd25aaa2552e8b3e208448c/ouroboros-consensus-cardano/src/shelley/Ouroboros/Consensus/Shelley/Protocol/Praos.hs#L125 sigBytes := header.Signature.([]byte) // Ref: https://github.com/IntersectMBO/cardano-ledger/blob/master/libs/cardano-protocol-tpraos/src/Cardano/Protocol/TPraos/BHeader.hs#L189 diff --git a/ledger/verify_vrf.go b/ledger/verify_vrf.go index 92111e60..09d671d8 100644 --- a/ledger/verify_vrf.go +++ b/ledger/verify_vrf.go @@ -43,20 +43,29 @@ func MkInputVrf(slot int64, eta0 []byte) []byte { h, err := blake2b.New(32, nil) if err != nil { panic( - fmt.Sprintf("unexpected error creating empty blake2b hash: %s", err), + fmt.Sprintf( + "unexpected error creating empty blake2b hash: %s", + err, + ), ) } h.Write(concat) return h.Sum(nil) } -func VrfVerifyAndHash(publicKey []byte, proof []byte, msg []byte) ([]byte, error) { +func VrfVerifyAndHash( + publicKey []byte, + proof []byte, + msg []byte, +) ([]byte, error) { Y := &edwards25519.Point{} // validate key if _, err := Y.SetBytes(publicKey); err != nil { return nil, err } - isSmallOrder := (&edwards25519.Point{}).MultByCofactor(Y).Equal(edwards25519.NewIdentityPoint()) == 1 + isSmallOrder := (&edwards25519.Point{}).MultByCofactor(Y). + Equal(edwards25519.NewIdentityPoint()) == + 1 if isSmallOrder { return nil, fmt.Errorf("public key is a small order point") } @@ -76,7 +85,9 @@ func vrfVerify(Y *edwards25519.Point, pi []byte, alpha []byte) (bool, error) { var U, V *edwards25519.Point // ge25519_p3 H_point, Gamma_point, U_point, V_point, tmp_p3_point; var tmp1, tmp2 *edwards25519.Point - Gamma, cScalar, sScalar, err := vrfIetfdraft03DecodeProof(pi) // _vrf_ietfdraft03_decode_proof(&Gamma_point, c_scalar, s_scalar, pi) != 0 + Gamma, cScalar, sScalar, err := vrfIetfdraft03DecodeProof( + pi, + ) // _vrf_ietfdraft03_decode_proof(&Gamma_point, c_scalar, s_scalar, pi) != 0 if err != nil { return false, err } @@ -110,9 +121,17 @@ func vrfVerify(Y *edwards25519.Point, pi []byte, alpha []byte) (bool, error) { V = &edwards25519.Point{} V.Subtract(tmp1, tmp2) - cprime := vrfHashPoints(H, Gamma, U, V) // _vrf_ietfdraft03_hash_points(cprime, &H_point, &Gamma_point, &U_point, &V_point); - - cmp := subtle.ConstantTimeCompare(cScalar[:], cprime.Bytes()) // return crypto_verify_16(c_scalar, cprime); + cprime := vrfHashPoints( + H, + Gamma, + U, + V, + ) // _vrf_ietfdraft03_hash_points(cprime, &H_point, &Gamma_point, &U_point, &V_point); + + cmp := subtle.ConstantTimeCompare( + cScalar[:], + cprime.Bytes(), + ) // return crypto_verify_16(c_scalar, cprime); return cmp == 1, nil } @@ -155,7 +174,9 @@ func cryptoVrfIetfdraft03ProofToHash(pi []byte) ([]byte, error) { return h.Sum(nil), nil } -func vrfIetfdraft03DecodeProof(pi []byte) (gamma *edwards25519.Point, c []byte, s []byte, err error) { +func vrfIetfdraft03DecodeProof( + pi []byte, +) (gamma *edwards25519.Point, c []byte, s []byte, err error) { if len(pi) != 80 { return nil, nil, nil, fmt.Errorf("unexpected length of pi (must be 80)") } @@ -169,7 +190,10 @@ func vrfIetfdraft03DecodeProof(pi []byte) (gamma *edwards25519.Point, c []byte, return gamma, c, s, nil } -func vrfHashToCurveElligator225519(Y *edwards25519.Point, alpha []byte) (*edwards25519.Point, error) { +func vrfHashToCurveElligator225519( + Y *edwards25519.Point, + alpha []byte, +) (*edwards25519.Point, error) { hs := sha512.New() hs.Write([]byte{VRF_SUITE}) @@ -231,21 +255,40 @@ func ge25519FromUniform(r []byte) ([]byte, error) { eIsMinus1 = int(s[1] & 1) // e_is_minus_1 = s[1] & 1; eIsNotMinus1 := eIsMinus1 ^ 1 - negx = new(field.Element).Negate(x) // fe25519_neg(negx, x); - x.Select(x, negx, eIsNotMinus1) // fe25519_cmov(x, negx, e_is_minus_1); - x2.Zero() // fe25519_0(x2); - x2.Select(x2, curve25519AElement, eIsNotMinus1) // fe25519_cmov(x2, curve25519_A, e_is_minus_1); - x.Subtract(x, x2) // fe25519_sub(x, x, x2); + negx = new(field.Element).Negate(x) // fe25519_neg(negx, x); + x.Select( + x, + negx, + eIsNotMinus1, + ) // fe25519_cmov(x, negx, e_is_minus_1); + x2.Zero() // fe25519_0(x2); + x2.Select( + x2, + curve25519AElement, + eIsNotMinus1, + ) // fe25519_cmov(x2, curve25519_A, e_is_minus_1); + x.Subtract(x, x2) // fe25519_sub(x, x, x2); // yed = (x-1)/(x+1) { var one, xPlusOne, xPlusOneInv, xMinusOne, yed *field.Element - one = (&field.Element{}).One() // fe25519_1(one); - xPlusOne = (&field.Element{}).Add(x, one) // fe25519_add(x_plus_one, x, one); - xMinusOne = (&field.Element{}).Subtract(x, one) // fe25519_sub(x_minus_one, x, one); - xPlusOneInv = (&field.Element{}).Invert(xPlusOne) // fe25519_invert(x_plus_one_inv, x_plus_one); - yed = (&field.Element{}).Multiply(xMinusOne, xPlusOneInv) // fe25519_mul(yed, x_minus_one, x_plus_one_inv); - s = yed.Bytes() // fe25519_tobytes(s, yed); + one = (&field.Element{}).One() // fe25519_1(one); + xPlusOne = (&field.Element{}).Add( + x, + one, + ) // fe25519_add(x_plus_one, x, one); + xMinusOne = (&field.Element{}).Subtract( + x, + one, + ) // fe25519_sub(x_minus_one, x, one); + xPlusOneInv = (&field.Element{}).Invert( + xPlusOne, + ) // fe25519_invert(x_plus_one_inv, x_plus_one); + yed = (&field.Element{}).Multiply( + xMinusOne, + xPlusOneInv, + ) // fe25519_mul(yed, x_minus_one, x_plus_one_inv); + s = yed.Bytes() // fe25519_tobytes(s, yed); } // recover x diff --git a/protocol/blockfetch/blockfetch.go b/protocol/blockfetch/blockfetch.go index 6c992afa..c329d4a6 100644 --- a/protocol/blockfetch/blockfetch.go +++ b/protocol/blockfetch/blockfetch.go @@ -132,7 +132,9 @@ func WithBlockFunc(blockFunc BlockFunc) BlockFetchOptionFunc { } } -func WithRequestRangeFunc(requestRangeFunc RequestRangeFunc) BlockFetchOptionFunc { +func WithRequestRangeFunc( + requestRangeFunc RequestRangeFunc, +) BlockFetchOptionFunc { return func(c *Config) { c.RequestRangeFunc = requestRangeFunc } diff --git a/protocol/blockfetch/client_test.go b/protocol/blockfetch/client_test.go index cd67bdc2..cd6e26e2 100644 --- a/protocol/blockfetch/client_test.go +++ b/protocol/blockfetch/client_test.go @@ -41,7 +41,11 @@ var conversationHandshakeRequestRange = []ouroboros_mock.ConversationEntry{ type testInnerFunc func(*testing.T, *ouroboros.Connection) -func runTest(t *testing.T, conversation []ouroboros_mock.ConversationEntry, innerFunc testInnerFunc) { +func runTest( + t *testing.T, + conversation []ouroboros_mock.ConversationEntry, + innerFunc testInnerFunc, +) { defer goleak.VerifyNone(t) mockConn := ouroboros_mock.NewConnection( ouroboros_mock.ProtocolRoleClient, @@ -151,10 +155,18 @@ func TestGetBlock(t *testing.T) { t.Fatalf("received unexpected error: %s", err) } if blk.Hash() != testBlock.Hash() { - t.Fatalf("did not receive expected block hash: got %s, wanted %s", blk.Hash(), testBlock.Hash()) + t.Fatalf( + "did not receive expected block hash: got %s, wanted %s", + blk.Hash(), + testBlock.Hash(), + ) } if blk.SlotNumber() != testBlockSlot { - t.Fatalf("did not receive expected block slot: got %d, wanted %d", blk.SlotNumber(), testBlockSlot) + t.Fatalf( + "did not receive expected block slot: got %d, wanted %d", + blk.SlotNumber(), + testBlockSlot, + ) } }, ) @@ -186,7 +198,11 @@ func TestGetBlockNoBlocks(t *testing.T) { t.Fatalf("did not receive expected error") } if err.Error() != expectedErr { - t.Fatalf("did not receive expected error\n got: %s\n wanted: %s", err, expectedErr) + t.Fatalf( + "did not receive expected error\n got: %s\n wanted: %s", + err, + expectedErr, + ) } }, ) diff --git a/protocol/blockfetch/server.go b/protocol/blockfetch/server.go index 3dc84d81..e48de64d 100644 --- a/protocol/blockfetch/server.go +++ b/protocol/blockfetch/server.go @@ -110,7 +110,11 @@ func (s *Server) handleRequestRange(msg protocol.Message) error { ) } msgRequestRange := msg.(*MsgRequestRange) - return s.config.RequestRangeFunc(s.callbackContext, msgRequestRange.Start, msgRequestRange.End) + return s.config.RequestRangeFunc( + s.callbackContext, + msgRequestRange.Start, + msgRequestRange.End, + ) } func (s *Server) handleClientDone() error { diff --git a/protocol/chainsync/chainsync.go b/protocol/chainsync/chainsync.go index 89b367b6..a52d1a5c 100644 --- a/protocol/chainsync/chainsync.go +++ b/protocol/chainsync/chainsync.go @@ -217,6 +217,7 @@ type CallbackContext struct { // Callback function types type RollBackwardFunc func(CallbackContext, common.Point, Tip) error type RollForwardFunc func(CallbackContext, uint, interface{}, Tip) error + type FindIntersectFunc func(CallbackContext, []common.Point) (common.Point, Tip, error) type RequestNextFunc func(CallbackContext) error @@ -269,7 +270,9 @@ func WithRollForwardFunc(rollForwardFunc RollForwardFunc) ChainSyncOptionFunc { } // WithFindIntersectFunc specifies the FindIntersect callback function -func WithFindIntersectFunc(findIntersectFunc FindIntersectFunc) ChainSyncOptionFunc { +func WithFindIntersectFunc( + findIntersectFunc FindIntersectFunc, +) ChainSyncOptionFunc { return func(c *Config) { c.FindIntersectFunc = findIntersectFunc } diff --git a/protocol/chainsync/client.go b/protocol/chainsync/client.go index f2a4bded..66b1f3f9 100644 --- a/protocol/chainsync/client.go +++ b/protocol/chainsync/client.go @@ -43,7 +43,11 @@ type Client struct { } // NewClient returns a new ChainSync client object -func NewClient(stateContext interface{}, protoOptions protocol.ProtocolOptions, cfg *Config) *Client { +func NewClient( + stateContext interface{}, + protoOptions protocol.ProtocolOptions, + cfg *Config, +) *Client { // Use node-to-client protocol ID ProtocolId := ProtocolIdNtC msgFromCborFunc := NewMsgFromCborNtC @@ -305,7 +309,8 @@ func (c *Client) handleAwaitReply() error { } func (c *Client) handleRollForward(msgGeneric protocol.Message) error { - if (c.config == nil || c.config.RollForwardFunc == nil) && !c.wantFirstBlock { + if (c.config == nil || c.config.RollForwardFunc == nil) && + !c.wantFirstBlock { return fmt.Errorf( "received chain-sync RollForward message but no callback function is defined", ) @@ -349,7 +354,12 @@ func (c *Client) handleRollForward(msgGeneric protocol.Message) error { return nil } // Call the user callback function - callbackErr = c.config.RollForwardFunc(c.callbackContext, blockType, blockHeader, msg.Tip) + callbackErr = c.config.RollForwardFunc( + c.callbackContext, + blockType, + blockHeader, + msg.Tip, + ) } else { msg := msgGeneric.(*MsgRollForwardNtC) blk, err := ledger.NewBlockFromCbor(msg.BlockType(), msg.BlockCbor()) diff --git a/protocol/chainsync/client_test.go b/protocol/chainsync/client_test.go index d3844d94..7cf9da53 100644 --- a/protocol/chainsync/client_test.go +++ b/protocol/chainsync/client_test.go @@ -43,7 +43,11 @@ var conversationHandshakeFindIntersect = []ouroboros_mock.ConversationEntry{ type testInnerFunc func(*testing.T, *ouroboros.Connection) -func runTest(t *testing.T, conversation []ouroboros_mock.ConversationEntry, innerFunc testInnerFunc) { +func runTest( + t *testing.T, + conversation []ouroboros_mock.ConversationEntry, + innerFunc testInnerFunc, +) { defer goleak.VerifyNone(t) mockConn := ouroboros_mock.NewConnection( ouroboros_mock.ProtocolRoleClient, @@ -124,7 +128,11 @@ func TestIntersectNotFound(t *testing.T) { t.Fatalf("did not receive expected error") } if err != chainsync.IntersectNotFoundError { - t.Fatalf("did not receive expected error\n got: %s\n wanted: %s", err, chainsync.IntersectNotFoundError) + t.Fatalf( + "did not receive expected error\n got: %s\n wanted: %s", + err, + chainsync.IntersectNotFoundError, + ) } }, ) @@ -157,7 +165,11 @@ func TestGetCurrentTip(t *testing.T) { t.Fatalf("received unexpected error: %s", err) } if !reflect.DeepEqual(tip, &expectedTip) { - t.Fatalf("did not receive expected tip\n got: %#v\n wanted: %#v", tip, expectedTip) + t.Fatalf( + "did not receive expected tip\n got: %#v\n wanted: %#v", + tip, + expectedTip, + ) } }, ) @@ -234,15 +246,25 @@ func TestGetAvailableBlockRange(t *testing.T) { t, conversation, func(t *testing.T, oConn *ouroboros.Connection) { - start, end, err := oConn.ChainSync().Client.GetAvailableBlockRange([]ocommon.Point{expectedIntersect}) + start, end, err := oConn.ChainSync().Client.GetAvailableBlockRange( + []ocommon.Point{expectedIntersect}, + ) if err != nil { t.Fatalf("received unexpected error: %s", err) } if !reflect.DeepEqual(start, expectedStart) { - t.Fatalf("did not receive expected start point\n got: %#v\n wanted: %#v", start, expectedStart) + t.Fatalf( + "did not receive expected start point\n got: %#v\n wanted: %#v", + start, + expectedStart, + ) } if !reflect.DeepEqual(end, expectedTip.Point) { - t.Fatalf("did not receive expected end point\n got: %#v\n wanted: %#v", end, expectedTip.Point) + t.Fatalf( + "did not receive expected end point\n got: %#v\n wanted: %#v", + end, + expectedTip.Point, + ) } }, ) diff --git a/protocol/chainsync/server.go b/protocol/chainsync/server.go index 2c820a15..e1f42b73 100644 --- a/protocol/chainsync/server.go +++ b/protocol/chainsync/server.go @@ -32,7 +32,11 @@ type Server struct { } // NewServer returns a new ChainSync server object -func NewServer(stateContext interface{}, protoOptions protocol.ProtocolOptions, cfg *Config) *Server { +func NewServer( + stateContext interface{}, + protoOptions protocol.ProtocolOptions, + cfg *Config, +) *Server { s := &Server{ config: cfg, // Save these for re-use later @@ -137,7 +141,10 @@ func (s *Server) handleFindIntersect(msg protocol.Message) error { ) } msgFindIntersect := msg.(*MsgFindIntersect) - point, tip, err := s.config.FindIntersectFunc(s.callbackContext, msgFindIntersect.Points) + point, tip, err := s.config.FindIntersectFunc( + s.callbackContext, + msgFindIntersect.Points, + ) if err != nil { if err == IntersectNotFoundError { msgResp := NewMsgIntersectNotFound(tip) diff --git a/protocol/handshake/client.go b/protocol/handshake/client.go index 828796ff..5c949e2b 100644 --- a/protocol/handshake/client.go +++ b/protocol/handshake/client.go @@ -100,11 +100,17 @@ func (c *Client) handleAcceptVersion(msg protocol.Message) error { } msgAcceptVersion := msg.(*MsgAcceptVersion) protoVersion := protocol.GetProtocolVersion(msgAcceptVersion.Version) - versionData, err := protoVersion.NewVersionDataFromCborFunc(msgAcceptVersion.VersionData) + versionData, err := protoVersion.NewVersionDataFromCborFunc( + msgAcceptVersion.VersionData, + ) if err != nil { return err } - return c.config.FinishedFunc(c.callbackContext, msgAcceptVersion.Version, versionData) + return c.config.FinishedFunc( + c.callbackContext, + msgAcceptVersion.Version, + versionData, + ) } func (c *Client) handleRefuse(msgGeneric protocol.Message) error { diff --git a/protocol/handshake/client_test.go b/protocol/handshake/client_test.go index 3c9dc607..2baea06a 100644 --- a/protocol/handshake/client_test.go +++ b/protocol/handshake/client_test.go @@ -113,10 +113,18 @@ func TestClientNtCAccept(t *testing.T) { // Check negotiated version and version data protoVersion, protoVersionData := oConn.ProtocolVersion() if protoVersion != mockProtocolVersionNtC { - t.Fatalf("did not get expected protocol version: got %d, wanted %d", protoVersion, mockProtocolVersionNtC) + t.Fatalf( + "did not get expected protocol version: got %d, wanted %d", + protoVersion, + mockProtocolVersionNtC, + ) } if !reflect.DeepEqual(protoVersionData, mockNtCVersionData()) { - t.Fatalf("did not get expected protocol version data:\n got: %#v\n wanted: %#v", protoVersionData, mockNtCVersionData()) + t.Fatalf( + "did not get expected protocol version data:\n got: %#v\n wanted: %#v", + protoVersionData, + mockNtCVersionData(), + ) } // Close Ouroboros connection if err := oConn.Close(); err != nil { @@ -159,10 +167,18 @@ func TestClientNtNAccept(t *testing.T) { // Check negotiated version and version data protoVersion, protoVersionData := oConn.ProtocolVersion() if protoVersion != mockProtocolVersionNtN { - t.Fatalf("did not get expected protocol version: got %d, wanted %d", protoVersion, mockProtocolVersionNtN) + t.Fatalf( + "did not get expected protocol version: got %d, wanted %d", + protoVersion, + mockProtocolVersionNtN, + ) } if !reflect.DeepEqual(protoVersionData, mockNtNVersionData()) { - t.Fatalf("did not get expected protocol version data:\n got: %#v\n wanted: %#v", protoVersionData, mockNtNVersionData()) + t.Fatalf( + "did not get expected protocol version data:\n got: %#v\n wanted: %#v", + protoVersionData, + mockNtNVersionData(), + ) } // Close Ouroboros connection if err := oConn.Close(); err != nil { @@ -205,10 +221,18 @@ func TestClientNtNAcceptV11(t *testing.T) { // Check negotiated version and version data protoVersion, protoVersionData := oConn.ProtocolVersion() if protoVersion != mockProtocolVersionNtNV11 { - t.Fatalf("did not get expected protocol version: got %d, wanted %d", protoVersion, mockProtocolVersionNtNV11) + t.Fatalf( + "did not get expected protocol version: got %d, wanted %d", + protoVersion, + mockProtocolVersionNtNV11, + ) } if !reflect.DeepEqual(protoVersionData, mockNtNVersionDataV11()) { - t.Fatalf("did not get expected protocol version data:\n got: %#v\n wanted: %#v", protoVersionData, mockNtNVersionDataV11()) + t.Fatalf( + "did not get expected protocol version data:\n got: %#v\n wanted: %#v", + protoVersionData, + mockNtNVersionDataV11(), + ) } // Close Ouroboros connection if err := oConn.Close(); err != nil { diff --git a/protocol/handshake/handshake.go b/protocol/handshake/handshake.go index bc325f6e..33202ce4 100644 --- a/protocol/handshake/handshake.go +++ b/protocol/handshake/handshake.go @@ -111,7 +111,9 @@ func NewConfig(options ...HandshakeOptionFunc) Config { } // WithProtocolVersionMap specifies the supported protocol versions -func WithProtocolVersionMap(versionMap protocol.ProtocolVersionMap) HandshakeOptionFunc { +func WithProtocolVersionMap( + versionMap protocol.ProtocolVersionMap, +) HandshakeOptionFunc { return func(c *Config) { c.ProtocolVersionMap = versionMap } diff --git a/protocol/handshake/server.go b/protocol/handshake/server.go index 98bacde4..866b6477 100644 --- a/protocol/handshake/server.go +++ b/protocol/handshake/server.go @@ -142,7 +142,11 @@ func (s *Server) handleProposeVersions(msg protocol.Message) error { } // Check network magic if proposedVersionData.NetworkMagic() != versionData.NetworkMagic() { - errMsg := fmt.Sprintf("network magic mismatch: %#v /= %#v", versionData, proposedVersionData) + errMsg := fmt.Sprintf( + "network magic mismatch: %#v /= %#v", + versionData, + proposedVersionData, + ) msgRefuse := NewMsgRefuse( []any{ RefuseReasonRefused, @@ -164,5 +168,9 @@ func (s *Server) handleProposeVersions(msg protocol.Message) error { if err := s.SendMessage(msgAcceptVersion); err != nil { return err } - return s.config.FinishedFunc(s.callbackContext, proposedVersion, proposedVersionData) + return s.config.FinishedFunc( + s.callbackContext, + proposedVersion, + proposedVersionData, + ) } diff --git a/protocol/handshake/server_test.go b/protocol/handshake/server_test.go index 8b4ac7aa..f3692144 100644 --- a/protocol/handshake/server_test.go +++ b/protocol/handshake/server_test.go @@ -37,9 +37,15 @@ func TestServerBasicHandshake(t *testing.T) { Messages: []protocol.Message{ handshake.NewMsgProposeVersions( protocol.ProtocolVersionMap{ - (10 + protocol.ProtocolVersionNtCOffset): protocol.VersionDataNtC9to14(ouroboros_mock.MockNetworkMagic), - (11 + protocol.ProtocolVersionNtCOffset): protocol.VersionDataNtC9to14(ouroboros_mock.MockNetworkMagic), - (12 + protocol.ProtocolVersionNtCOffset): protocol.VersionDataNtC9to14(ouroboros_mock.MockNetworkMagic), + (10 + protocol.ProtocolVersionNtCOffset): protocol.VersionDataNtC9to14( + ouroboros_mock.MockNetworkMagic, + ), + (11 + protocol.ProtocolVersionNtCOffset): protocol.VersionDataNtC9to14( + ouroboros_mock.MockNetworkMagic, + ), + (12 + protocol.ProtocolVersionNtCOffset): protocol.VersionDataNtC9to14( + ouroboros_mock.MockNetworkMagic, + ), }, ), }, @@ -51,7 +57,9 @@ func TestServerBasicHandshake(t *testing.T) { MsgFromCborFunc: handshake.NewMsgFromCbor, Message: handshake.NewMsgAcceptVersion( (12 + protocol.ProtocolVersionNtCOffset), - protocol.VersionDataNtC9to14(ouroboros_mock.MockNetworkMagic), + protocol.VersionDataNtC9to14( + ouroboros_mock.MockNetworkMagic, + ), ), }, }, @@ -89,7 +97,9 @@ func TestServerHandshakeRefuseVersionMismatch(t *testing.T) { defer func() { goleak.VerifyNone(t) }() - expectedErr := fmt.Errorf("handshake failed: refused due to version mismatch") + expectedErr := fmt.Errorf( + "handshake failed: refused due to version mismatch", + ) mockConn := ouroboros_mock.NewConnection( ouroboros_mock.ProtocolRoleServer, []ouroboros_mock.ConversationEntry{ @@ -99,9 +109,15 @@ func TestServerHandshakeRefuseVersionMismatch(t *testing.T) { Messages: []protocol.Message{ handshake.NewMsgProposeVersions( protocol.ProtocolVersionMap{ - (100 + protocol.ProtocolVersionNtCOffset): protocol.VersionDataNtC9to14(ouroboros_mock.MockNetworkMagic), - (101 + protocol.ProtocolVersionNtCOffset): protocol.VersionDataNtC9to14(ouroboros_mock.MockNetworkMagic), - (102 + protocol.ProtocolVersionNtCOffset): protocol.VersionDataNtC9to14(ouroboros_mock.MockNetworkMagic), + (100 + protocol.ProtocolVersionNtCOffset): protocol.VersionDataNtC9to14( + ouroboros_mock.MockNetworkMagic, + ), + (101 + protocol.ProtocolVersionNtCOffset): protocol.VersionDataNtC9to14( + ouroboros_mock.MockNetworkMagic, + ), + (102 + protocol.ProtocolVersionNtCOffset): protocol.VersionDataNtC9to14( + ouroboros_mock.MockNetworkMagic, + ), }, ), }, diff --git a/protocol/keepalive/client_test.go b/protocol/keepalive/client_test.go index ec2002d5..dda2004b 100644 --- a/protocol/keepalive/client_test.go +++ b/protocol/keepalive/client_test.go @@ -46,7 +46,9 @@ var ConversationKeepAliveWrongResponse = []ouroboros_mock.ConversationEntry{ ProtocolId: keepalive.ProtocolId, IsResponse: true, Messages: []protocol.Message{ - keepalive.NewMsgKeepAliveResponse(MockKeepAliveWrongCookie), // Incorrect Cookie value + keepalive.NewMsgKeepAliveResponse( + MockKeepAliveWrongCookie, + ), // Incorrect Cookie value }, }, } @@ -55,8 +57,10 @@ var ConversationKeepAliveDifferentCookie = []ouroboros_mock.ConversationEntry{ ouroboros_mock.ConversationEntryHandshakeRequestGeneric, ouroboros_mock.ConversationEntryHandshakeNtNResponse, ouroboros_mock.ConversationEntryInput{ - ProtocolId: keepalive.ProtocolId, - Message: keepalive.NewMsgKeepAlive(MockKeepAliveDifferentCookie), + ProtocolId: keepalive.ProtocolId, + Message: keepalive.NewMsgKeepAlive( + MockKeepAliveDifferentCookie, + ), MsgFromCborFunc: keepalive.NewMsgFromCbor, }, ouroboros_mock.ConversationEntryOutput{ diff --git a/protocol/localstatequery/client.go b/protocol/localstatequery/client.go index dd5a6297..a056f454 100644 --- a/protocol/localstatequery/client.go +++ b/protocol/localstatequery/client.go @@ -582,7 +582,9 @@ func (c *Client) GetRewardProvenance() (*RewardProvenanceResult, error) { return &result, nil } -func (c *Client) GetUTxOByTxIn(txIns []ledger.TransactionInput) (*UTxOByTxInResult, error) { +func (c *Client) GetUTxOByTxIn( + txIns []ledger.TransactionInput, +) (*UTxOByTxInResult, error) { c.busyMutex.Lock() defer c.busyMutex.Unlock() currentEra, err := c.getCurrentEra() diff --git a/protocol/localstatequery/client_test.go b/protocol/localstatequery/client_test.go index 2d7f129f..dcacde35 100644 --- a/protocol/localstatequery/client_test.go +++ b/protocol/localstatequery/client_test.go @@ -65,7 +65,11 @@ var conversationCurrentEra = append( type testInnerFunc func(*testing.T, *ouroboros.Connection) -func runTest(t *testing.T, conversation []ouroboros_mock.ConversationEntry, innerFunc testInnerFunc) { +func runTest( + t *testing.T, + conversation []ouroboros_mock.ConversationEntry, + innerFunc testInnerFunc, +) { defer goleak.VerifyNone(t) mockConn := ouroboros_mock.NewConnection( ouroboros_mock.ProtocolRoleClient, @@ -130,7 +134,11 @@ func TestGetCurrentEra(t *testing.T) { t.Fatalf("received unexpected error: %s", err) } if currentEra != 5 { - t.Fatalf("did not receive expected result: got %d, expected %d", currentEra, 5) + t.Fatalf( + "did not receive expected result: got %d, expected %d", + currentEra, + 5, + ) } }, ) @@ -165,7 +173,11 @@ func TestGetChainPoint(t *testing.T) { t.Fatalf("received unexpected error: %s", err) } if !reflect.DeepEqual(chainPoint, &expectedPoint) { - t.Fatalf("did not receive expected result\n got: %#v\n wanted: %#v", chainPoint, expectedPoint) + t.Fatalf( + "did not receive expected result\n got: %#v\n wanted: %#v", + chainPoint, + expectedPoint, + ) } }, ) @@ -199,14 +211,20 @@ func TestGetEpochNo(t *testing.T) { t.Fatalf("received unexpected error: %s", err) } if epochNo != expectedEpochNo { - t.Fatalf("did not receive expected result, got %d, wanted %d", epochNo, expectedEpochNo) + t.Fatalf( + "did not receive expected result, got %d, wanted %d", + epochNo, + expectedEpochNo, + ) } }, ) } func TestGetUTxOByAddress(t *testing.T) { - testAddress, err := ledger.NewAddress("addr_test1vrk294czhxhglflvxla7vxj2cjz7wyrdpxl3fj0vych5wws77xuc7") + testAddress, err := ledger.NewAddress( + "addr_test1vrk294czhxhglflvxla7vxj2cjz7wyrdpxl3fj0vych5wws77xuc7", + ) if err != nil { t.Fatalf("unexpected error: %s", err) } @@ -246,7 +264,9 @@ func TestGetUTxOByAddress(t *testing.T) { t, conversation, func(t *testing.T, oConn *ouroboros.Connection) { - utxos, err := oConn.LocalStateQuery().Client.GetUTxOByAddress([]ledger.Address{testAddress}) + utxos, err := oConn.LocalStateQuery().Client.GetUTxOByAddress( + []ledger.Address{testAddress}, + ) if err != nil { t.Fatalf("received unexpected error: %s", err) } @@ -256,7 +276,11 @@ func TestGetUTxOByAddress(t *testing.T) { utxos.Results[k] = v } if !reflect.DeepEqual(utxos, &expectedResult) { - t.Fatalf("did not receive expected result\n got: %#v\n wanted: %#v", utxos, expectedResult) + t.Fatalf( + "did not receive expected result\n got: %#v\n wanted: %#v", + utxos, + expectedResult, + ) } }, ) diff --git a/protocol/localtxmonitor/client_test.go b/protocol/localtxmonitor/client_test.go index 8b84893f..b5ec45d9 100644 --- a/protocol/localtxmonitor/client_test.go +++ b/protocol/localtxmonitor/client_test.go @@ -48,7 +48,11 @@ var conversationHandshakeAcquire = []ouroboros_mock.ConversationEntry{ type testInnerFunc func(*testing.T, *ouroboros.Connection) -func runTest(t *testing.T, conversation []ouroboros_mock.ConversationEntry, innerFunc testInnerFunc) { +func runTest( + t *testing.T, + conversation []ouroboros_mock.ConversationEntry, + innerFunc testInnerFunc, +) { defer goleak.VerifyNone(t) mockConn := ouroboros_mock.NewConnection( ouroboros_mock.ProtocolRoleClient, @@ -128,7 +132,11 @@ func TestHasTxTrue(t *testing.T) { t.Fatalf("received unexpected error: %s", err) } if hasTx != expectedResult { - t.Fatalf("did not receive expected HasTx result: got %v, wanted %v", hasTx, expectedResult) + t.Fatalf( + "did not receive expected HasTx result: got %v, wanted %v", + hasTx, + expectedResult, + ) } }, ) @@ -160,7 +168,11 @@ func TestHasTxFalse(t *testing.T) { t.Fatalf("received unexpected error: %s", err) } if hasTx != expectedResult { - t.Fatalf("did not receive expected HasTx result: got %v, wanted %v", hasTx, expectedResult) + t.Fatalf( + "did not receive expected HasTx result: got %v, wanted %v", + hasTx, + expectedResult, + ) } }, ) @@ -197,13 +209,25 @@ func TestGetSizes(t *testing.T) { t.Fatalf("received unexpected error: %s", err) } if capacity != expectedCapacity { - t.Fatalf("did not receive expected capacity result: got %d, wanted %d", capacity, expectedCapacity) + t.Fatalf( + "did not receive expected capacity result: got %d, wanted %d", + capacity, + expectedCapacity, + ) } if size != expectedSize { - t.Fatalf("did not receive expected size result: got %d, wanted %d", size, expectedSize) + t.Fatalf( + "did not receive expected size result: got %d, wanted %d", + size, + expectedSize, + ) } if txCount != expectedTxCount { - t.Fatalf("did not receive expected TX count result: got %d, wanted %d", txCount, expectedTxCount) + t.Fatalf( + "did not receive expected TX count result: got %d, wanted %d", + txCount, + expectedTxCount, + ) } }, ) @@ -253,14 +277,22 @@ func TestNextTx(t *testing.T) { t.Fatalf("received unexpected error: %s", err) } if !reflect.DeepEqual(tx1, expectedTx1) { - t.Fatalf("did not get expected TX content\n got: %x\n wanted: %x", tx1, expectedTx1) + t.Fatalf( + "did not get expected TX content\n got: %x\n wanted: %x", + tx1, + expectedTx1, + ) } tx2, err := oConn.LocalTxMonitor().Client.NextTx() if err != nil { t.Fatalf("received unexpected error: %s", err) } if !reflect.DeepEqual(tx2, expectedTx2) { - t.Fatalf("did not get expected TX content\n got: %x\n wanted: %x", tx2, expectedTx2) + t.Fatalf( + "did not get expected TX content\n got: %x\n wanted: %x", + tx2, + expectedTx2, + ) } }, ) diff --git a/protocol/localtxmonitor/server.go b/protocol/localtxmonitor/server.go index 498f9776..6d4cd5bf 100644 --- a/protocol/localtxmonitor/server.go +++ b/protocol/localtxmonitor/server.go @@ -89,7 +89,9 @@ func (s *Server) handleAcquire() error { ) } // Call the user callback function to get mempool information - mempoolSlotNumber, mempoolCapacity, mempoolTxs, err := s.config.GetMempoolFunc(s.callbackContext) + mempoolSlotNumber, mempoolCapacity, mempoolTxs, err := s.config.GetMempoolFunc( + s.callbackContext, + ) if err != nil { return err } diff --git a/protocol/localtxsubmission/client_test.go b/protocol/localtxsubmission/client_test.go index f67fb301..63dcdaed 100644 --- a/protocol/localtxsubmission/client_test.go +++ b/protocol/localtxsubmission/client_test.go @@ -39,7 +39,11 @@ var conversationHandshakeSubmitTx = []ouroboros_mock.ConversationEntry{ type testInnerFunc func(*testing.T, *ouroboros.Connection) -func runTest(t *testing.T, conversation []ouroboros_mock.ConversationEntry, innerFunc testInnerFunc) { +func runTest( + t *testing.T, + conversation []ouroboros_mock.ConversationEntry, + innerFunc testInnerFunc, +) { defer goleak.VerifyNone(t) mockConn := ouroboros_mock.NewConnection( ouroboros_mock.ProtocolRoleClient, @@ -109,7 +113,10 @@ func TestSubmitTxAccept(t *testing.T) { t, conversation, func(t *testing.T, oConn *ouroboros.Connection) { - err := oConn.LocalTxSubmission().Client.SubmitTx(ledger.TxTypeBabbage, testTx) + err := oConn.LocalTxSubmission().Client.SubmitTx( + ledger.TxTypeBabbage, + testTx, + ) if err != nil { t.Fatalf("received unexpected error: %s", err) } @@ -138,12 +145,19 @@ func TestSubmitTxRject(t *testing.T) { t, conversation, func(t *testing.T, oConn *ouroboros.Connection) { - err := oConn.LocalTxSubmission().Client.SubmitTx(ledger.TxTypeBabbage, testTx) + err := oConn.LocalTxSubmission().Client.SubmitTx( + ledger.TxTypeBabbage, + testTx, + ) if err == nil { t.Fatalf("did not receive expected error") } if err.Error() != expectedErr.Error() { - t.Fatalf("did not receive expected error\n got: %s\n wanted: %s", err, expectedErr) + t.Fatalf( + "did not receive expected error\n got: %s\n wanted: %s", + err, + expectedErr, + ) } }, ) diff --git a/protocol/peersharing/peersharing.go b/protocol/peersharing/peersharing.go index 45d76f33..d89bb063 100644 --- a/protocol/peersharing/peersharing.go +++ b/protocol/peersharing/peersharing.go @@ -110,7 +110,9 @@ func NewConfig(options ...PeerSharingOptionFunc) Config { } // WithShareRequestFunc specifies the ShareRequest callback function -func WithShareRequestFunc(shareRequestFunc ShareRequestFunc) PeerSharingOptionFunc { +func WithShareRequestFunc( + shareRequestFunc ShareRequestFunc, +) PeerSharingOptionFunc { return func(c *Config) { c.ShareRequestFunc = shareRequestFunc } diff --git a/protocol/peersharing/server.go b/protocol/peersharing/server.go index ed25eafe..32dc1973 100644 --- a/protocol/peersharing/server.go +++ b/protocol/peersharing/server.go @@ -83,7 +83,10 @@ func (s *Server) handleShareRequest(msg protocol.Message) error { ) } msgShareRequest := msg.(*MsgShareRequest) - peers, err := s.config.ShareRequestFunc(s.callbackContext, int(msgShareRequest.Amount)) + peers, err := s.config.ShareRequestFunc( + s.callbackContext, + int(msgShareRequest.Amount), + ) if err != nil { return err } diff --git a/protocol/protocol.go b/protocol/protocol.go index dd95201c..a329af88 100644 --- a/protocol/protocol.go +++ b/protocol/protocol.go @@ -441,7 +441,9 @@ func (p *Protocol) stateLoop(ch <-chan protocolStateTransition) { // Set timeout for state transition if p.config.StateMap[currentState].Timeout > 0 { - transitionTimer = time.NewTimer(p.config.StateMap[currentState].Timeout) + transitionTimer = time.NewTimer( + p.config.StateMap[currentState].Timeout, + ) } } getTimerChan := func() <-chan time.Time {