Skip to content

Commit

Permalink
Merge branch 'main' into wm-optimizations
Browse files Browse the repository at this point in the history
# Conflicts:
#	pkg/maintainer/wallet/chain_test.go
#	pkg/maintainer/wallet/redemptions.go
  • Loading branch information
lukasz-zimnoch committed Jul 4, 2023
2 parents 3d5e9c8 + fc1bbf3 commit 56335a1
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 37 deletions.
12 changes: 6 additions & 6 deletions pkg/chain/ethereum/tbtc.go
Original file line number Diff line number Diff line change
Expand Up @@ -1529,17 +1529,17 @@ func (tc *TbtcChain) GetWalletLock(
func parseWalletActionType(value uint8) (tbtc.WalletActionType, error) {
switch value {
case 0:
return tbtc.Noop, nil
return tbtc.ActionNoop, nil
case 1:
return tbtc.Heartbeat, nil
return tbtc.ActionHeartbeat, nil
case 2:
return tbtc.DepositSweep, nil
return tbtc.ActionDepositSweep, nil
case 3:
return tbtc.Redemption, nil
return tbtc.ActionRedemption, nil
case 4:
return tbtc.MovingFunds, nil
return tbtc.ActionMovingFunds, nil
case 5:
return tbtc.MovedFundsSweep, nil
return tbtc.ActionMovedFundsSweep, nil
default:
return 0, fmt.Errorf("unexpected wallet action value: [%v]", value)
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/maintainer/wallet/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import (
"encoding/binary"
"encoding/hex"
"fmt"
"github.com/keep-network/keep-core/pkg/bitcoin"
"github.com/keep-network/keep-core/pkg/chain"
"math/big"
"sync"
"time"

"github.com/keep-network/keep-core/pkg/bitcoin"
"github.com/keep-network/keep-core/pkg/chain"
"github.com/keep-network/keep-core/pkg/tbtc"
)

Expand Down Expand Up @@ -427,7 +427,7 @@ func (lc *LocalChain) GetWalletLock(

walletLock, ok := lc.walletLocks[walletPublicKeyHash]
if !ok {
return time.Time{}, tbtc.Noop, fmt.Errorf("no lock configured for given wallet")
return time.Time{}, tbtc.ActionNoop, fmt.Errorf("no lock configured for given wallet")
}

return walletLock.lockExpiration, walletLock.walletAction, nil
Expand Down Expand Up @@ -455,7 +455,7 @@ func (lc *LocalChain) ResetWalletLock(

lc.walletLocks[walletPublicKeyHash] = &walletLock{
lockExpiration: time.Unix(0, 0),
walletAction: tbtc.Noop,
walletAction: tbtc.ActionNoop,
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/maintainer/wallet/deposit_sweep.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (wm *walletMaintainer) runDepositSweepTask(ctx context.Context) error {
return wm.runIfWalletUnlocked(
ctx,
walletPublicKeyHash,
tbtc.DepositSweep,
tbtc.ActionDepositSweep,
func() error {
return ProposeDepositsSweep(
wm.chain,
Expand Down
2 changes: 1 addition & 1 deletion pkg/maintainer/wallet/redemptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (wm *walletMaintainer) runRedemptionTask(ctx context.Context) error {
err = wm.runIfWalletUnlocked(
ctx,
walletPublicKeyHash,
tbtc.Redemption,
tbtc.ActionRedemption,
func() error {
return ProposeRedemption(
wm.chain,
Expand Down
6 changes: 3 additions & 3 deletions pkg/maintainer/wallet/wallet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestRunIfWalletUnlocked_WhenLocked(t *testing.T) {
localChain.SetWalletLock(
walletPublicKeyHash,
lockExpiration,
tbtc.Heartbeat,
tbtc.ActionHeartbeat,
)

runFunc := func() error {
Expand All @@ -35,7 +35,7 @@ func TestRunIfWalletUnlocked_WhenLocked(t *testing.T) {
err := wm.runIfWalletUnlocked(
context.Background(),
walletPublicKeyHash,
tbtc.DepositSweep,
tbtc.ActionDepositSweep,
runFunc,
)
if err != nil {
Expand Down Expand Up @@ -75,7 +75,7 @@ func TestRunIfWalletUnlocked_WhenUnlocked(t *testing.T) {
err := wm.runIfWalletUnlocked(
context.Background(),
walletPublicKeyHash,
tbtc.DepositSweep,
tbtc.ActionDepositSweep,
runFunc,
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/tbtc/deposit_sweep.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ func (dsa *depositSweepAction) wallet() wallet {
}

func (dsa *depositSweepAction) actionType() WalletActionType {
return DepositSweep
return ActionDepositSweep
}

// assembleDepositSweepTransaction constructs an unsigned deposit sweep Bitcoin
Expand Down
2 changes: 1 addition & 1 deletion pkg/tbtc/heartbeat.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,5 @@ func (ha *heartbeatAction) wallet() wallet {
}

func (ha *heartbeatAction) actionType() WalletActionType {
return Heartbeat
return ActionHeartbeat
}
6 changes: 3 additions & 3 deletions pkg/tbtc/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ func (n *node) handleHeartbeatRequest(

walletActionLogger := logger.With(
zap.String("wallet", fmt.Sprintf("0x%x", walletPublicKeyBytes)),
zap.String("action", Heartbeat.String()),
zap.String("action", ActionHeartbeat.String()),
zap.Uint64("startBlock", heartbeatRequestProcessingStartBlock),
)
walletActionLogger.Infof("dispatching wallet action")
Expand Down Expand Up @@ -435,7 +435,7 @@ func (n *node) handleDepositSweepProposal(

walletActionLogger := logger.With(
zap.String("wallet", fmt.Sprintf("0x%x", walletPublicKeyBytes)),
zap.String("action", DepositSweep.String()),
zap.String("action", ActionDepositSweep.String()),
zap.Uint64("startBlock", proposalProcessingStartBlock),
)
walletActionLogger.Infof("dispatching wallet action")
Expand Down Expand Up @@ -522,7 +522,7 @@ func (n *node) handleRedemptionProposal(

walletActionLogger := logger.With(
zap.String("wallet", fmt.Sprintf("0x%x", walletPublicKeyBytes)),
zap.String("action", Redemption.String()),
zap.String("action", ActionRedemption.String()),
zap.Uint64("startBlock", proposalProcessingStartBlock),
)
walletActionLogger.Infof("dispatching wallet action")
Expand Down
2 changes: 1 addition & 1 deletion pkg/tbtc/redemption.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ func (ra *redemptionAction) wallet() wallet {
}

func (ra *redemptionAction) actionType() WalletActionType {
return Redemption
return ActionRedemption
}

// redemptionFeeDistributionFn calculates the redemption transaction fee
Expand Down
6 changes: 3 additions & 3 deletions pkg/tbtc/tbtc.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ func Initialize(

// The event is confirmed if the wallet is locked due to a heartbeat
// action.
if time.Now().Before(expiresAt) && cause == Heartbeat {
if time.Now().Before(expiresAt) && cause == ActionHeartbeat {
logger.Infof(
"heartbeat request submitted for "+
"wallet PKH [0x%x] at block [%v] by [%v]",
Expand Down Expand Up @@ -432,7 +432,7 @@ func Initialize(

// The event is confirmed if the wallet is locked due to a deposit
// sweep action.
if time.Now().Before(expiresAt) && cause == DepositSweep {
if time.Now().Before(expiresAt) && cause == ActionDepositSweep {
logger.Infof(
"deposit sweep proposal submitted for "+
"wallet PKH [0x%x] at block [%v] by [%v]",
Expand Down Expand Up @@ -532,7 +532,7 @@ func Initialize(

// The event is confirmed if the wallet is locked due to a
// redemption action.
if time.Now().Before(expiresAt) && cause == Redemption {
if time.Now().Before(expiresAt) && cause == ActionRedemption {
logger.Infof(
"redemption proposal submitted for "+
"wallet PKH [0x%x] at block [%v] by [%v]",
Expand Down
24 changes: 12 additions & 12 deletions pkg/tbtc/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,27 @@ import (
type WalletActionType uint8

const (
Noop WalletActionType = iota
Heartbeat
DepositSweep
Redemption
MovingFunds
MovedFundsSweep
ActionNoop WalletActionType = iota
ActionHeartbeat
ActionDepositSweep
ActionRedemption
ActionMovingFunds
ActionMovedFundsSweep
)

func (wat WalletActionType) String() string {
switch wat {
case Noop:
case ActionNoop:
return "Noop"
case Heartbeat:
case ActionHeartbeat:
return "Heartbeat"
case DepositSweep:
case ActionDepositSweep:
return "DepositSweep"
case Redemption:
case ActionRedemption:
return "Redemption"
case MovingFunds:
case ActionMovingFunds:
return "MovingFunds"
case MovedFundsSweep:
case ActionMovedFundsSweep:
return "MovedFundsSweep"
default:
panic("unknown wallet action type")
Expand Down
2 changes: 1 addition & 1 deletion pkg/tbtc/wallet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func (mwa *mockWalletAction) wallet() wallet {
}

func (mwa *mockWalletAction) actionType() WalletActionType {
return Noop
return ActionNoop
}

func generateWallet(privateKey *big.Int) wallet {
Expand Down

0 comments on commit 56335a1

Please sign in to comment.