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
1 change: 1 addition & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,7 @@ func New(
keys[btcbridgetypes.MemStoreKey],
govAuthor,
app.BankKeeper,
app.StakingKeeper,
)
btcbridgeModule := btcbridge.NewAppModule(appCodec, app.BtcBridgeKeeper)

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ require (
github.com/cometbft/cometbft v0.37.4
github.com/cometbft/cometbft-db v0.8.0
github.com/cosmos/btcutil v1.0.5
github.com/cosmos/cosmos-proto v1.0.0-beta.4
github.com/cosmos/cosmos-sdk v0.47.5
github.com/cosmos/gogoproto v1.4.10
github.com/cosmos/ibc-go/v7 v7.3.0
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0
github.com/golang/protobuf v1.5.3
github.com/gorilla/mux v1.8.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
Expand Down Expand Up @@ -66,7 +68,6 @@ require (
github.com/cockroachdb/redact v1.1.5 // indirect
github.com/coinbase/rosetta-sdk-go/types v1.0.0 // indirect
github.com/confio/ics23/go v0.9.0 // indirect
github.com/cosmos/cosmos-proto v1.0.0-beta.4 // indirect
github.com/cosmos/go-bip39 v1.0.0 // indirect
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/cosmos/iavl v0.20.1 // indirect
Expand All @@ -78,7 +79,6 @@ require (
github.com/danieljoos/wincred v1.1.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/decred/dcrd/crypto/blake256 v1.0.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f // indirect
github.com/dgraph-io/badger/v2 v2.2007.4 // indirect
github.com/dgraph-io/ristretto v0.1.1 // indirect
Expand Down
47 changes: 47 additions & 0 deletions proto/side/btcbridge/bitcoin.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ syntax = "proto3";
package side.btcbridge;

import "gogoproto/gogo.proto";
import "google/protobuf/any.proto";
import "google/protobuf/timestamp.proto";
import "cosmos/base/v1beta1/coin.proto";
import "cosmos_proto/cosmos.proto";
import "side/btcbridge/params.proto";

option go_package = "github.com/sideprotocol/side/x/btcbridge/types";

Expand Down Expand Up @@ -56,3 +60,46 @@ message Edict {
string amount = 2;
uint32 output = 3;
}

// DKG Participant
message DKGParticipant {
// the moniker of the corresponding validator
string moniker = 1;
// the operator address of the corresponding validator
string address = 2;
}

enum DKGRequestStatus {
// DKG_REQUEST_STATUS_UNSPECIFIED defines the unknown DKG request status
DKG_REQUEST_STATUS_UNSPECIFIED = 0;
// DKG_REQUEST_STATUS_PENDING defines the status of the DKG request which is pending
DKG_REQUEST_STATUS_PENDING = 1;
// DKG_REQUEST_STATUS_COMPLETED defines the status of the DKG request which is completed
DKG_REQUEST_STATUS_COMPLETED = 2;
// DKG_REQUEST_STATUS_FAILED defines the status of the DKG request which failed
DKG_REQUEST_STATUS_FAILED = 3;
}

// DKG Request
message DKGRequest {
// the unique request id
uint64 id = 1;
// participant set
repeated DKGParticipant participants = 2;
// threshold required to perform DKG
uint32 threshold = 3;
// expiration time
google.protobuf.Timestamp expiration = 4 [(gogoproto.stdtime) = true, (gogoproto.nullable) = true];
// status
DKGRequestStatus status = 5;
}

// DKG Completion Request
message DKGCompletionRequest {
// request id
uint64 id = 1;
// sender
string sender = 2;
// new vaults generated by DKG
repeated Vault vaults = 3;
}
12 changes: 10 additions & 2 deletions proto/side/btcbridge/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ message Params {
int64 network_fee = 7;
// Reward epoch for relayer and TSS participant incentivization
google.protobuf.Duration reward_epoch = 8 [(gogoproto.stdduration) = true];
// Transition period after which TSS participants update process is completed
google.protobuf.Duration tss_update_transition_period = 9 [(gogoproto.stdduration) = true];
// TSS params
TSSParams tss_params = 9;
}

// AssetType defines the type of asset
Expand Down Expand Up @@ -72,3 +72,11 @@ message ProtocolFees {
// Protocol fee collector
string collector = 3;
}

// TSSParams defines the params related to TSS
message TSSParams {
// timeout duration for DKG request
google.protobuf.Duration dkg_timeout_period = 1 [(gogoproto.stdduration) = true];
// Transition period after which TSS participants update process is completed
google.protobuf.Duration participant_update_transition_period = 2 [(gogoproto.stdduration) = true];
}
55 changes: 55 additions & 0 deletions proto/side/btcbridge/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,22 @@ service Query {
rpc QueryWithdrawRequestByTxHash(QueryWithdrawRequestByTxHashRequest) returns (QueryWithdrawRequestByTxHashResponse) {
option (google.api.http).get = "/side/btcbridge/withdrawal/request/tx/{txid}";
}
// QueryDKGRequest queries the DKG request by the given id.
rpc QueryDKGRequest(QueryDKGRequestRequest) returns (QueryDKGRequestResponse) {
option (google.api.http).get = "/side/btcbridge/dkg/request/{id}";
}
// QueryDKGRequests queries the DKG requests by the given status
rpc QueryDKGRequests(QueryDKGRequestsRequest) returns (QueryDKGRequestsResponse) {
option (google.api.http).get = "/side/btcbridge/dkg/request";
}
// QueryAllDKGRequests queries all DKG requests.
rpc QueryAllDKGRequests(QueryAllDKGRequestsRequest) returns (QueryAllDKGRequestsResponse) {
option (google.api.http).get = "/side/btcbridge/dkg/requests";
}
// QueryDKGCompletionRequests queries DKG completion requests by the given id.
rpc QueryDKGCompletionRequests(QueryDKGCompletionRequestsRequest) returns (QueryDKGCompletionRequestsResponse) {
option (google.api.http).get = "/side/btcbridge/dkg/completion/request/{id}";
}
}

// QueryWithdrawRequestsRequest is request type for the Query/WithdrawRequests RPC method.
Expand Down Expand Up @@ -112,3 +128,42 @@ message QueryBlockHeaderByHashRequest {
message QueryBlockHeaderByHashResponse {
BlockHeader block_header = 1;
}

// QueryDKGRequestRequest is the request type for the Query/DKGRequest RPC method.
message QueryDKGRequestRequest {
uint64 id = 1;
}

// QueryDKGRequestResponse is the response type for the Query/DKGRequest RPC method.
message QueryDKGRequestResponse {
DKGRequest request = 1;
}

// QueryDKGRequestsRequest is the request type for the Query/DKGRequests RPC method.
message QueryDKGRequestsRequest {
DKGRequestStatus status = 1;
}

// QueryDKGRequestsResponse is the response type for the Query/DKGRequests RPC method.
message QueryDKGRequestsResponse {
repeated DKGRequest requests = 1;
}

// QueryAllDKGRequestsRequest is the request type for the Query/AllDKGRequests RPC method.
message QueryAllDKGRequestsRequest {
}

// QueryAllDKGRequestsResponse is the response type for the Query/AllDKGRequests RPC method.
message QueryAllDKGRequestsResponse {
repeated DKGRequest requests = 1;
}

// QueryDKGCompletionRequestsRequest is the request type for the Query/DKGCompletionRequests RPC method.
message QueryDKGCompletionRequestsRequest {
uint64 id = 1;
}

// QueryDKGCompletionRequestsResponse is the response type for the Query/DKGCompletionRequests RPC method.
message QueryDKGCompletionRequestsResponse {
repeated DKGCompletionRequest requests = 1;
}
30 changes: 30 additions & 0 deletions proto/side/btcbridge/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ service Msg {
rpc WithdrawToBitcoin (MsgWithdrawToBitcoin) returns (MsgWithdrawToBitcoinResponse);
// SubmitWithdrawStatus submits the status of the withdraw transaction.
rpc SubmitWithdrawStatus (MsgSubmitWithdrawStatus) returns (MsgSubmitWithdrawStatusResponse);
// InitiateDKG initiates the DKG request.
rpc InitiateDKG (MsgInitiateDKG) returns (MsgInitiateDKGResponse);
// CompleteDKG completes the given DKG request.
rpc CompleteDKG (MsgCompleteDKG) returns (MsgCompleteDKGResponse);
// UpdateParams defines a governance operation for updating the x/btcbridge module
// parameters. The authority defaults to the x/gov module account.
//
Expand Down Expand Up @@ -93,6 +97,32 @@ message MsgWithdrawToBitcoin {
message MsgWithdrawToBitcoinResponse {
}

// MsgInitiateDKG is the Msg/InitiateDKG request type.
message MsgInitiateDKG {
// authority is the address that controls the module (defaults to x/gov unless overwritten).
string authority = 1;
// expected participant set
repeated DKGParticipant participants = 2;
// threshold required to perform DKG
uint32 threshold = 3;
}

// MsgInitiateDKGResponse defines the Msg/InitiateDKG response type.
message MsgInitiateDKGResponse {}

// MsgCompleteDKG is the Msg/CompleteDKG request type.
message MsgCompleteDKG {
// the sender is expected to be the validator which participates in DKG
string sender = 1;
// request id
uint64 id = 2;
// new vaults generated by DKG
repeated Vault vaults = 3;
}

// MsgCompleteDKGResponse defines the Msg/CompleteDKG response type.
message MsgCompleteDKGResponse {}

// MsgUpdateParams is the Msg/UpdateParams request type.
//
// Since: cosmos-sdk 0.47
Expand Down
1 change: 1 addition & 0 deletions testutil/keeper/btc_bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func BtcBridgeKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
memStoreKey,
authority,
app.BankKeeper,
app.StakingKeeper,
)

ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger())
Expand Down
38 changes: 38 additions & 0 deletions x/btcbridge/abci.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package btcbridge

import (
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/sideprotocol/side/x/btcbridge/keeper"
"github.com/sideprotocol/side/x/btcbridge/types"
)

// EndBlocker called at every block to handle DKG requests
func EndBlocker(ctx sdk.Context, k keeper.Keeper) {
pendingDKGRequests := k.GetPendingDKGRequests(ctx)

for _, req := range pendingDKGRequests {
// check if the DKG request expired
if !ctx.BlockTime().Before(*req.Expiration) {
req.Status = types.DKGRequestStatus_DKG_REQUEST_STATUS_FAILED
continue
}

// handle DKG completion requests
completionRequests := k.GetDKGCompletionRequests(ctx, req.Id)
if len(completionRequests) != len(req.Participants) {
continue
}

// check if the DKG completion requests are valid
if !types.CheckCompletionRequests(completionRequests) {
req.Status = types.DKGRequestStatus_DKG_REQUEST_STATUS_FAILED
continue
}

req.Status = types.DKGRequestStatus_DKG_REQUEST_STATUS_COMPLETED

// update vaults
k.UpdateVaults(ctx, completionRequests[0].Vaults)
}
}
15 changes: 9 additions & 6 deletions x/btcbridge/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ type (

authority string

bankKeeper types.BankKeeper
bankKeeper types.BankKeeper
stakingKeeper types.StakingKeeper
}
)

Expand All @@ -34,13 +35,15 @@ func NewKeeper(
memKey storetypes.StoreKey,
authority string,
bankKeeper types.BankKeeper,
stakingKeeper types.StakingKeeper,
) *Keeper {
return &Keeper{
cdc: cdc,
storeKey: storeKey,
memKey: memKey,
authority: authority,
bankKeeper: bankKeeper,
cdc: cdc,
storeKey: storeKey,
memKey: memKey,
authority: authority,
bankKeeper: bankKeeper,
stakingKeeper: stakingKeeper,
}
}

Expand Down
Loading