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

style: fix long lines using golines #453

Closed
wants to merge 1 commit into from
Closed
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
24 changes: 21 additions & 3 deletions clientcontroller/api/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,31 @@ type ClientController interface {
type ConsumerController interface {
// CommitPubRandList commits a list of EOTS public randomness the consumer chain
// it returns tx hash and error
CommitPubRandList(fpPk *btcec.PublicKey, startHeight uint64, numPubRand uint64, commitment []byte, sig *schnorr.Signature) (*types.TxResponse, error)
CommitPubRandList(
fpPk *btcec.PublicKey,
startHeight uint64,
numPubRand uint64,
commitment []byte,
sig *schnorr.Signature,
) (*types.TxResponse, error)

// SubmitFinalitySig submits the finality signature to the consumer chain
SubmitFinalitySig(fpPk *btcec.PublicKey, block *types.BlockInfo, pubRand *btcec.FieldVal, proof []byte, sig *btcec.ModNScalar) (*types.TxResponse, error)
SubmitFinalitySig(
fpPk *btcec.PublicKey,
block *types.BlockInfo,
pubRand *btcec.FieldVal,
proof []byte,
sig *btcec.ModNScalar,
) (*types.TxResponse, error)

// SubmitBatchFinalitySigs submits a batch of finality signatures to the consumer chain
SubmitBatchFinalitySigs(fpPk *btcec.PublicKey, blocks []*types.BlockInfo, pubRandList []*btcec.FieldVal, proofList [][]byte, sigs []*btcec.ModNScalar) (*types.TxResponse, error)
SubmitBatchFinalitySigs(
fpPk *btcec.PublicKey,
blocks []*types.BlockInfo,
pubRandList []*btcec.FieldVal,
proofList [][]byte,
sigs []*btcec.ModNScalar,
) (*types.TxResponse, error)

// Note: the following queries are only for PoC

Expand Down
82 changes: 66 additions & 16 deletions clientcontroller/babylon/babylon.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,19 @@ func (bc *BabylonController) GetKeyAddress() sdk.AccAddress {
return addr
}

func (bc *BabylonController) reliablySendMsg(msg sdk.Msg, expectedErrs []*sdkErr.Error, unrecoverableErrs []*sdkErr.Error) (*provider.RelayerTxResponse, error) {
func (bc *BabylonController) reliablySendMsg(
msg sdk.Msg,
expectedErrs []*sdkErr.Error,
unrecoverableErrs []*sdkErr.Error,
) (*provider.RelayerTxResponse, error) {
return bc.reliablySendMsgs([]sdk.Msg{msg}, expectedErrs, unrecoverableErrs)
}

func (bc *BabylonController) reliablySendMsgs(msgs []sdk.Msg, expectedErrs []*sdkErr.Error, unrecoverableErrs []*sdkErr.Error) (*provider.RelayerTxResponse, error) {
func (bc *BabylonController) reliablySendMsgs(
msgs []sdk.Msg,
expectedErrs []*sdkErr.Error,
unrecoverableErrs []*sdkErr.Error,
) (*provider.RelayerTxResponse, error) {
return bc.bbnClient.ReliablySendMsgs(
context.Background(),
msgs,
Expand Down Expand Up @@ -150,7 +158,11 @@ func (bc *BabylonController) QueryFinalityProviderSlashed(fpPk *btcec.PublicKey)
fpPubKey := bbntypes.NewBIP340PubKeyFromBTCPK(fpPk)
res, err := bc.bbnClient.QueryClient.FinalityProvider(fpPubKey.MarshalHex())
if err != nil {
return false, fmt.Errorf("failed to query the finality provider %s: %v", fpPubKey.MarshalHex(), err)
return false, fmt.Errorf(
"failed to query the finality provider %s: %v",
fpPubKey.MarshalHex(),
err,
)
}

slashed := res.FinalityProvider.SlashedBtcHeight > 0
Expand All @@ -159,7 +171,10 @@ func (bc *BabylonController) QueryFinalityProviderSlashed(fpPk *btcec.PublicKey)
}

// QueryFinalityProviderVotingPower queries the voting power of the finality provider at a given height
func (bc *BabylonController) QueryFinalityProviderVotingPower(fpPk *btcec.PublicKey, blockHeight uint64) (uint64, error) {
func (bc *BabylonController) QueryFinalityProviderVotingPower(
fpPk *btcec.PublicKey,
blockHeight uint64,
) (uint64, error) {
res, err := bc.bbnClient.QueryClient.FinalityProviderPowerAtHeight(
bbntypes.NewBIP340PubKeyFromBTCPK(fpPk).MarshalHex(),
blockHeight,
Expand All @@ -175,18 +190,34 @@ func (bc *BabylonController) QueryLatestFinalizedBlocks(count uint64) ([]*types.
return bc.queryLatestBlocks(nil, count, finalitytypes.QueriedBlockStatus_FINALIZED, true)
}

func (bc *BabylonController) QueryBlocks(startHeight, endHeight, limit uint64) ([]*types.BlockInfo, error) {
func (bc *BabylonController) QueryBlocks(
startHeight, endHeight, limit uint64,
) ([]*types.BlockInfo, error) {
if endHeight < startHeight {
return nil, fmt.Errorf("the startHeight %v should not be higher than the endHeight %v", startHeight, endHeight)
return nil, fmt.Errorf(
"the startHeight %v should not be higher than the endHeight %v",
startHeight,
endHeight,
)
}
count := endHeight - startHeight + 1
if count > limit {
count = limit
}
return bc.queryLatestBlocks(sdk.Uint64ToBigEndian(startHeight), count, finalitytypes.QueriedBlockStatus_ANY, false)
return bc.queryLatestBlocks(
sdk.Uint64ToBigEndian(startHeight),
count,
finalitytypes.QueriedBlockStatus_ANY,
false,
)
}

func (bc *BabylonController) queryLatestBlocks(startKey []byte, count uint64, status finalitytypes.QueriedBlockStatus, reverse bool) ([]*types.BlockInfo, error) {
func (bc *BabylonController) queryLatestBlocks(
startKey []byte,
count uint64,
status finalitytypes.QueriedBlockStatus,
reverse bool,
) ([]*types.BlockInfo, error) {
var blocks []*types.BlockInfo
pagination := &sdkquery.PageRequest{
Limit: count,
Expand Down Expand Up @@ -268,7 +299,9 @@ func (bc *BabylonController) CreateBTCDelegation(
return &types.TxResponse{TxHash: res.TxHash}, nil
}

func (bc *BabylonController) InsertBtcBlockHeaders(headers []bbntypes.BTCHeaderBytes) (*provider.RelayerTxResponse, error) {
func (bc *BabylonController) InsertBtcBlockHeaders(
headers []bbntypes.BTCHeaderBytes,
) (*provider.RelayerTxResponse, error) {
msg := &btclctypes.MsgInsertHeaders{
Signer: bc.MustGetTxSigner(),
Headers: headers,
Expand Down Expand Up @@ -307,7 +340,9 @@ func (bc *BabylonController) QueryFinalityProviders() ([]*btcstakingtypes.Finali
return fps, nil
}

func (bc *BabylonController) QueryConsumerFinalityProviders(consumerId string) ([]*bsctypes.FinalityProviderResponse, error) {
func (bc *BabylonController) QueryConsumerFinalityProviders(
consumerId string,
) ([]*bsctypes.FinalityProviderResponse, error) {
var fps []*bsctypes.FinalityProviderResponse
pagination := &sdkquery.PageRequest{
Limit: 100,
Expand Down Expand Up @@ -348,18 +383,25 @@ func (bc *BabylonController) QueryVotesAtHeight(height uint64) ([]bbntypes.BIP34
return res.BtcPks, nil
}

func (bc *BabylonController) QueryPendingDelegations(limit uint64) ([]*btcstakingtypes.BTCDelegationResponse, error) {
func (bc *BabylonController) QueryPendingDelegations(
limit uint64,
) ([]*btcstakingtypes.BTCDelegationResponse, error) {
return bc.queryDelegationsWithStatus(btcstakingtypes.BTCDelegationStatus_PENDING, limit)
}

func (bc *BabylonController) QueryActiveDelegations(limit uint64) ([]*btcstakingtypes.BTCDelegationResponse, error) {
func (bc *BabylonController) QueryActiveDelegations(
limit uint64,
) ([]*btcstakingtypes.BTCDelegationResponse, error) {
return bc.queryDelegationsWithStatus(btcstakingtypes.BTCDelegationStatus_ACTIVE, limit)
}

// queryDelegationsWithStatus queries BTC delegations
// with the given status (either pending or unbonding)
// it is only used when the program is running in Covenant mode
func (bc *BabylonController) queryDelegationsWithStatus(status btcstakingtypes.BTCDelegationStatus, limit uint64) ([]*btcstakingtypes.BTCDelegationResponse, error) {
func (bc *BabylonController) queryDelegationsWithStatus(
status btcstakingtypes.BTCDelegationStatus,
limit uint64,
) ([]*btcstakingtypes.BTCDelegationResponse, error) {
pagination := &sdkquery.PageRequest{
Limit: limit,
}
Expand Down Expand Up @@ -393,7 +435,10 @@ func (bc *BabylonController) QueryStakingParams() (*types.StakingParams, error)
}
covenantPks = append(covenantPks, covPk)
}
slashingAddress, err := btcutil.DecodeAddress(stakingParamRes.Params.SlashingAddress, bc.btcParams)
slashingAddress, err := btcutil.DecodeAddress(
stakingParamRes.Params.SlashingAddress,
bc.btcParams,
)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -436,7 +481,10 @@ func (bc *BabylonController) SubmitCovenantSigs(
return &types.TxResponse{TxHash: res.TxHash}, nil
}

func (bc *BabylonController) InsertSpvProofs(submitter string, proofs []*btcctypes.BTCSpvProof) (*provider.RelayerTxResponse, error) {
func (bc *BabylonController) InsertSpvProofs(
submitter string,
proofs []*btcctypes.BTCSpvProof,
) (*provider.RelayerTxResponse, error) {
msg := &btcctypes.MsgInsertBTCSpvProof{
Submitter: submitter,
Proofs: proofs,
Expand All @@ -451,7 +499,9 @@ func (bc *BabylonController) InsertSpvProofs(submitter string, proofs []*btcctyp
}

// RegisterConsumerChain registers a consumer chain via a MsgRegisterChain to Babylon
func (bc *BabylonController) RegisterConsumerChain(id, name, description string) (*types.TxResponse, error) {
func (bc *BabylonController) RegisterConsumerChain(
id, name, description string,
) (*types.TxResponse, error) {
msg := &bsctypes.MsgRegisterConsumer{
Signer: bc.MustGetTxSigner(),
ConsumerId: id,
Expand Down
57 changes: 47 additions & 10 deletions clientcontroller/babylon/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,19 @@ func (bc *BabylonConsumerController) GetKeyAddress() sdk.AccAddress {
return addr
}

func (bc *BabylonConsumerController) reliablySendMsg(msg sdk.Msg, expectedErrs []*sdkErr.Error, unrecoverableErrs []*sdkErr.Error) (*provider.RelayerTxResponse, error) {
func (bc *BabylonConsumerController) reliablySendMsg(
msg sdk.Msg,
expectedErrs []*sdkErr.Error,
unrecoverableErrs []*sdkErr.Error,
) (*provider.RelayerTxResponse, error) {
return bc.reliablySendMsgs([]sdk.Msg{msg}, expectedErrs, unrecoverableErrs)
}

func (bc *BabylonConsumerController) reliablySendMsgs(msgs []sdk.Msg, expectedErrs []*sdkErr.Error, unrecoverableErrs []*sdkErr.Error) (*provider.RelayerTxResponse, error) {
func (bc *BabylonConsumerController) reliablySendMsgs(
msgs []sdk.Msg,
expectedErrs []*sdkErr.Error,
unrecoverableErrs []*sdkErr.Error,
) (*provider.RelayerTxResponse, error) {
return bc.bbnClient.ReliablySendMsgs(
context.Background(),
msgs,
Expand Down Expand Up @@ -179,7 +187,11 @@ func (bc *BabylonConsumerController) SubmitBatchFinalitySigs(
sigs []*btcec.ModNScalar,
) (*types.TxResponse, error) {
if len(blocks) != len(sigs) {
return nil, fmt.Errorf("the number of blocks %v should match the number of finality signatures %v", len(blocks), len(sigs))
return nil, fmt.Errorf(
"the number of blocks %v should match the number of finality signatures %v",
len(blocks),
len(sigs),
)
}

msgs := make([]sdk.Msg, 0, len(blocks))
Expand Down Expand Up @@ -216,13 +228,20 @@ func (bc *BabylonConsumerController) SubmitBatchFinalitySigs(
}

// QueryFinalityProviderVotingPower queries the voting power of the finality provider at a given height
func (bc *BabylonConsumerController) QueryFinalityProviderVotingPower(fpPk *btcec.PublicKey, blockHeight uint64) (uint64, error) {
func (bc *BabylonConsumerController) QueryFinalityProviderVotingPower(
fpPk *btcec.PublicKey,
blockHeight uint64,
) (uint64, error) {
res, err := bc.bbnClient.QueryClient.FinalityProviderPowerAtHeight(
bbntypes.NewBIP340PubKeyFromBTCPK(fpPk).MarshalHex(),
blockHeight,
)
if err != nil {
return 0, fmt.Errorf("failed to query the finality provider's voting power at height %d: %w", blockHeight, err)
return 0, fmt.Errorf(
"failed to query the finality provider's voting power at height %d: %w",
blockHeight,
err,
)
}

return res.VotingPower, nil
Expand All @@ -236,18 +255,34 @@ func (bc *BabylonConsumerController) QueryLatestFinalizedBlock() (*types.BlockIn
return blocks[0], err
}

func (bc *BabylonConsumerController) QueryBlocks(startHeight, endHeight, limit uint64) ([]*types.BlockInfo, error) {
func (bc *BabylonConsumerController) QueryBlocks(
startHeight, endHeight, limit uint64,
) ([]*types.BlockInfo, error) {
if endHeight < startHeight {
return nil, fmt.Errorf("the startHeight %v should not be higher than the endHeight %v", startHeight, endHeight)
return nil, fmt.Errorf(
"the startHeight %v should not be higher than the endHeight %v",
startHeight,
endHeight,
)
}
count := endHeight - startHeight + 1
if count > limit {
count = limit
}
return bc.queryLatestBlocks(sdk.Uint64ToBigEndian(startHeight), count, finalitytypes.QueriedBlockStatus_ANY, false)
return bc.queryLatestBlocks(
sdk.Uint64ToBigEndian(startHeight),
count,
finalitytypes.QueriedBlockStatus_ANY,
false,
)
}

func (bc *BabylonConsumerController) queryLatestBlocks(startKey []byte, count uint64, status finalitytypes.QueriedBlockStatus, reverse bool) ([]*types.BlockInfo, error) {
func (bc *BabylonConsumerController) queryLatestBlocks(
startKey []byte,
count uint64,
status finalitytypes.QueriedBlockStatus,
reverse bool,
) ([]*types.BlockInfo, error) {
var blocks []*types.BlockInfo
pagination := &sdkquery.PageRequest{
Limit: count,
Expand Down Expand Up @@ -284,7 +319,9 @@ func (bc *BabylonConsumerController) QueryBlock(height uint64) (*types.BlockInfo
}

// QueryLastPublicRandCommit returns the last public randomness commitments
func (bc *BabylonConsumerController) QueryLastPublicRandCommit(fpPk *btcec.PublicKey) (*types.PubRandCommit, error) {
func (bc *BabylonConsumerController) QueryLastPublicRandCommit(
fpPk *btcec.PublicKey,
) (*types.PubRandCommit, error) {
fpBtcPk := bbntypes.NewBIP340PubKeyFromBTCPK(fpPk)

pagination := &sdkquery.PageRequest{
Expand Down
Loading