Skip to content

Commit

Permalink
Coordination proposal implementations
Browse files Browse the repository at this point in the history
This is the first step to integrate the existing proposal structures with
the new mechanism. Here we are making them compliant with the
`coordinationProposal` interface and moving them out of the `chain.go` file
to indicate that they are no longer pure chain components.
  • Loading branch information
lukasz-zimnoch committed Nov 24, 2023
1 parent 2c60764 commit cf07e7a
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 19 deletions.
24 changes: 6 additions & 18 deletions pkg/tbtc/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,26 +363,19 @@ type WalletCoordinatorChain interface {

// HeartbeatRequestSubmittedEvent represents a wallet heartbeat request
// submitted to the chain.
//
// TODO: Remove this type and all related code.
type HeartbeatRequestSubmittedEvent struct {
WalletPublicKeyHash [20]byte
Message []byte
Coordinator chain.Address
BlockNumber uint64
}

// DepositSweepProposal represents a deposit sweep proposal submitted to the chain.
type DepositSweepProposal struct {
WalletPublicKeyHash [20]byte
DepositsKeys []struct {
FundingTxHash bitcoin.Hash
FundingOutputIndex uint32
}
SweepTxFee *big.Int
DepositsRevealBlocks []*big.Int
}

// DepositSweepProposalSubmittedEvent represents a deposit sweep proposal
// submission event.
//
// TODO: Remove this type and all related code.
type DepositSweepProposalSubmittedEvent struct {
Proposal *DepositSweepProposal
Coordinator chain.Address
Expand All @@ -404,6 +397,8 @@ type DepositSweepProposalSubmittedEventFilter struct {

// RedemptionProposalSubmittedEvent represents a redemption proposal
// submission event.
//
// TODO: Remove this type and all related code.
type RedemptionProposalSubmittedEvent struct {
Proposal *RedemptionProposal
Coordinator chain.Address
Expand All @@ -423,13 +418,6 @@ type RedemptionProposalSubmittedEventFilter struct {
WalletPublicKeyHash [20]byte
}

// RedemptionProposal represents a redemption proposal submitted to the chain.
type RedemptionProposal struct {
WalletPublicKeyHash [20]byte
RedeemersOutputScripts []bitcoin.Script
RedemptionTxFee *big.Int
}

// RedemptionRequestedEvent represents a redemption requested event.
type RedemptionRequestedEvent struct {
WalletPublicKeyHash [20]byte
Expand Down
27 changes: 27 additions & 0 deletions pkg/tbtc/deposit_sweep.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tbtc
import (
"crypto/ecdsa"
"fmt"
"math/big"
"time"

"github.com/ipfs/go-log/v2"
Expand All @@ -12,6 +13,12 @@ import (
)

const (
// depositSweepProposalValidityBlocks determines the deposit sweep proposal
// validity time expressed in blocks. In other words, this is the worst-case
// time for a deposit sweep during which the wallet is busy and cannot take
// another actions. The value of 1200 blocks is roughly 4 hours, assuming
// 12 seconds per block.
depositSweepProposalValidityBlocks = 1200
// depositSweepProposalConfirmationBlocks determines the block length of the
// confirmation period on the host chain that is preserved after a deposit
// sweep proposal submission.
Expand Down Expand Up @@ -47,6 +54,26 @@ const (
depositSweepBroadcastCheckDelay = 1 * time.Minute
)

// DepositSweepProposal represents a deposit sweep proposal issued by a
// wallet's coordination leader.
type DepositSweepProposal struct {
WalletPublicKeyHash [20]byte
DepositsKeys []struct {
FundingTxHash bitcoin.Hash
FundingOutputIndex uint32
}
SweepTxFee *big.Int
DepositsRevealBlocks []*big.Int
}

func (dsp *DepositSweepProposal) actionType() WalletActionType {
return ActionDepositSweep
}

func (dsp *DepositSweepProposal) validityBlocks() uint64 {
return depositSweepProposalValidityBlocks
}

// depositSweepAction is a deposit sweep walletAction.
type depositSweepAction struct {
logger *zap.SugaredLogger
Expand Down
19 changes: 18 additions & 1 deletion pkg/tbtc/heartbeat.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@ import (
)

const (
// heartbeatProposalValidityBlocks determines the wallet heartbeat proposal
// validity time expressed in blocks. In other words, this is the worst-case
// time for a wallet heartbeat during which the wallet is busy and cannot
// take another actions. The value of 300 blocks is roughly 1 hour, assuming
// 12 seconds per block.
heartbeatProposalValidityBlocks = 300
// heartbeatRequestConfirmationBlocks determines the block length of the
// confirmation period on the host chain that is preserved after a heartbeat
// request submission.
heartbeatRequestConfirmationBlocks = 3

// heartbeatRequestTimeoutSafetyMargin determines the duration of the
// safety margin that must be preserved between the signing timeout
// and the timeout of the entire heartbeat action. This safety
Expand All @@ -25,6 +30,18 @@ const (
heartbeatRequestTimeoutSafetyMargin = 5 * time.Minute
)

type HeartbeatProposal struct {
// TODO: Proposal fields.
}

func (hp *HeartbeatProposal) actionType() WalletActionType {
return ActionHeartbeat
}

func (hp *HeartbeatProposal) validityBlocks() uint64 {
return heartbeatProposalValidityBlocks
}

// heartbeatSigningExecutor is an interface meant to decouple the specific
// implementation of the signing executor from the heartbeat action.
type heartbeatSigningExecutor interface {
Expand Down
23 changes: 23 additions & 0 deletions pkg/tbtc/redemption.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tbtc
import (
"crypto/ecdsa"
"fmt"
"math/big"
"time"

"go.uber.org/zap"
Expand All @@ -14,6 +15,12 @@ import (
)

const (
// redemptionProposalValidityBlocks determines the redemption proposal
// validity time expressed in blocks. In other words, this is the worst-case
// time for a redemption during which the wallet is busy and cannot take
// another actions. The value of 600 blocks is roughly 2 hours, assuming
// 12 seconds per block.
redemptionProposalValidityBlocks = 600
// redemptionProposalConfirmationBlocks determines the block length of the
// confirmation period on the host chain that is preserved after a
// redemption proposal submission.
Expand Down Expand Up @@ -44,6 +51,22 @@ const (
redemptionBroadcastCheckDelay = 1 * time.Minute
)

// RedemptionProposal represents a redemption proposal issued by a wallet's
// coordination leader.
type RedemptionProposal struct {
WalletPublicKeyHash [20]byte
RedeemersOutputScripts []bitcoin.Script
RedemptionTxFee *big.Int
}

func (rp *RedemptionProposal) actionType() WalletActionType {
return ActionRedemption
}

func (rp *RedemptionProposal) validityBlocks() uint64 {
return redemptionProposalValidityBlocks
}

// RedemptionTransactionShape is an enum describing the shape of
// a Bitcoin redemption transaction.
type RedemptionTransactionShape uint8
Expand Down

0 comments on commit cf07e7a

Please sign in to comment.