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

refactor(observer): disable Bitcoin witness support for mainnet (release/v19) #2838

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 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
38 changes: 29 additions & 9 deletions zetaclient/chains/bitcoin/observer/inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,12 @@
return "", err
}

// #nosec G115 always positive
event, err := GetBtcEventWithWitness(
// read the events
event, err := GetBtcEvent(

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L269 was not covered by tests
ob.btcClient,
*tx,
tss,
uint64(blockVb.Height),
uint64(blockVb.Height), // #nosec G115 always positive

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L273 was not covered by tests
ob.logger.Inbound,
ob.netParams,
depositorFee,
Expand Down Expand Up @@ -328,7 +328,7 @@
continue // the first tx is coinbase; we do not process coinbase tx
}

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

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L331 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,10 +390,28 @@
return false
}

// GetBtcEvent either returns a valid BTCInboundEvent or nil
// GetBtcEvent returns a valid BTCInboundEvent or nil
// it uses witness data to extract the sender address, except for mainnet
func GetBtcEvent(
rpcClient interfaces.BTCRPCClient,
tx btcjson.TxRawResult,
tssAddress string,
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 GetBtcEventWithWitness(rpcClient, tx, tssAddress, blockNumber, logger, netParams, depositorFee)

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L407 was not covered by tests
}

// GetBtcEventWithoutWitness either returns a valid BTCInboundEvent or nil
// This is the legacy version of GetBtcEvent that does not support witness data
// Note: the caller should retry the tx on error (e.g., GetSenderAddressByVin failed)
// TODO(revamp): simplify this function
func GetBtcEvent(
func GetBtcEventWithoutWitness(
rpcClient interfaces.BTCRPCClient,
tx btcjson.TxRawResult,
tssAddress string,
Expand Down Expand Up @@ -437,7 +455,7 @@
// deposit amount has to be no less than the minimum depositor fee
if vout0.Value < depositorFee {
logger.Info().
Msgf("GetBtcEvent: btc deposit amount %v in txid %s is less than depositor fee %v", vout0.Value, tx.Txid, depositorFee)
Msgf("GetBtcEventWithoutWitness: btc deposit amount %v in txid %s is less than depositor fee %v", vout0.Value, tx.Txid, depositorFee)
return nil, nil
}
value = vout0.Value - depositorFee
Expand All @@ -446,15 +464,17 @@
vout1 := tx.Vout[1]
memo, found, err = bitcoin.DecodeOpReturnMemo(vout1.ScriptPubKey.Hex, tx.Txid)
if err != nil {
logger.Error().Err(err).Msgf("GetBtcEvent: error decoding OP_RETURN memo: %s", vout1.ScriptPubKey.Hex)
logger.Error().
Err(err).
Msgf("GetBtcEventWithoutWitness: error decoding OP_RETURN memo: %s", vout1.ScriptPubKey.Hex)
return nil, nil
}
}
}
// event found, get sender address
if found {
if len(tx.Vin) == 0 { // should never happen
return nil, fmt.Errorf("GetBtcEvent: no input found for inbound: %s", tx.Txid)
return nil, fmt.Errorf("GetBtcEventWithoutWitness: no input found for inbound: %s", tx.Txid)
}

fromAddress, err := GetSenderAddressByVin(rpcClient, tx.Vin[0], netParams)
Expand Down
Loading
Loading