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

fix: skip deposit fee calculation if transaction doesn't involve TSS address #3161

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
37 changes: 16 additions & 21 deletions zetaclient/chains/bitcoin/observer/inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,6 @@
return "", fmt.Errorf("block %d is not confirmed yet", blockVb.Height)
}

// calculate depositor fee
depositorFee, err := bitcoin.CalcDepositorFee(ob.btcClient, tx, ob.netParams)
if err != nil {
return "", errors.Wrapf(err, "error calculating depositor fee for inbound %s", tx.Txid)
}

// #nosec G115 always positive
event, err := GetBtcEvent(
ob.btcClient,
Expand All @@ -268,7 +262,6 @@
uint64(blockVb.Height),
ob.logger.Inbound,
ob.netParams,
depositorFee,
)
if err != nil {
return "", err
Expand Down Expand Up @@ -322,13 +315,7 @@
continue // the first tx is coinbase; we do not process coinbase tx
}

// calculate depositor fee
depositorFee, err := bitcoin.CalcDepositorFee(rpcClient, &txs[idx], netParams)
if err != nil {
return nil, errors.Wrapf(err, "error calculating depositor fee for inbound %s", tx.Txid)
}

event, err := GetBtcEvent(rpcClient, tx, tssAddress, blockNumber, logger, netParams, depositorFee)
event, err := GetBtcEvent(rpcClient, tx, tssAddress, blockNumber, logger, netParams)

Check warning on line 318 in zetaclient/chains/bitcoin/observer/inbound.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/bitcoin/observer/inbound.go#L318

Added line #L318 was not covered by tests
if err != nil {
// unable to parse the tx, the caller should retry
return nil, errors.Wrapf(err, "error getting btc event for tx %s in block %d", tx.Txid, blockNumber)
Expand Down Expand Up @@ -390,12 +377,11 @@
blockNumber uint64,
logger zerolog.Logger,
netParams *chaincfg.Params,
depositorFee float64,
) (*BTCInboundEvent, error) {
if netParams.Name == chaincfg.MainNetParams.Name {
return GetBtcEventWithoutWitness(rpcClient, tx, tssAddress, blockNumber, logger, netParams, depositorFee)
return GetBtcEventWithoutWitness(rpcClient, tx, tssAddress, blockNumber, logger, netParams)

Check warning on line 382 in zetaclient/chains/bitcoin/observer/inbound.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/bitcoin/observer/inbound.go#L382

Added line #L382 was not covered by tests
}
return GetBtcEventWithWitness(rpcClient, tx, tssAddress, blockNumber, logger, netParams, depositorFee)
return GetBtcEventWithWitness(rpcClient, tx, tssAddress, blockNumber, logger, netParams)

Check warning on line 384 in zetaclient/chains/bitcoin/observer/inbound.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/bitcoin/observer/inbound.go#L384

Added line #L384 was not covered by tests
}

// GetBtcEventWithoutWitness either returns a valid BTCInboundEvent or nil
Expand All @@ -408,11 +394,14 @@
blockNumber uint64,
logger zerolog.Logger,
netParams *chaincfg.Params,
depositorFee float64,
) (*BTCInboundEvent, error) {
found := false
var value float64
var memo []byte
var (
found = false
CryptoFewka marked this conversation as resolved.
Show resolved Hide resolved
value float64
depositorFee float64
memo []byte
)

Check warning on line 404 in zetaclient/chains/bitcoin/observer/inbound.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/bitcoin/observer/inbound.go#L398-L404

Added lines #L398 - L404 were not covered by tests
if len(tx.Vout) >= 2 {
// 1st vout must have tss address as receiver with p2wpkh scriptPubKey
vout0 := tx.Vout[0]
Expand All @@ -429,6 +418,12 @@
return nil, nil
}

// calculate depositor fee
depositorFee, err := bitcoin.CalcDepositorFee(rpcClient, &tx, netParams)
if err != nil {
return nil, errors.Wrapf(err, "error calculating depositor fee for inbound %s", tx.Txid)
}

Check warning on line 425 in zetaclient/chains/bitcoin/observer/inbound.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/bitcoin/observer/inbound.go#L422-L425

Added lines #L422 - L425 were not covered by tests

// deposit amount has to be no less than the minimum depositor fee
if vout0.Value < depositorFee {
logger.Info().
Expand Down
Loading
Loading