spv

package
v1.21.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 1, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultHistoryDepth is the default value for history depth which is the
	// number of blocks to look back from the current block when searching for
	// past wallet-related events. The value is the approximate number of
	// Ethereum blocks in a week, assuming one block is 12s.
	DefaultHistoryDepth = 50400

	// DefaultTransactionLimit is the default value for the limit of
	// transactions returned for a given wallet public key hash. The value is
	// based on the frequency of how often wallet transactions will happen.
	// For example, deposit sweep transactions are assumed to happen every 48h.
	// Redemption transactions are assumed to happen every 3h. The wallet should
	// refuse any proposals from the coordinator if the previously executed
	// Bitcoin transaction was not proved to the Bridge yet so in theory, the
	// value of 1 should be enough. We make it a bit higher - better to be
	// safe than sorry.
	DefaultTransactionLimit = 20

	// DefaultRestartBackoffTime is the default value for restart back-off time.
	DefaultRestartBackoffTime = 30 * time.Minute

	// DefaultIdleBackOffTime is the default value for idle back-off time.
	DefaultIdleBackOffTime = 10 * time.Minute
)

Variables

This section is empty.

Functions

func Initialize

func Initialize(
	ctx context.Context,
	config Config,
	spvChain Chain,
	btcDiffChain btcdiff.Chain,
	btcChain bitcoin.Chain,
)

func SubmitDepositSweepProof

func SubmitDepositSweepProof(
	transactionHash bitcoin.Hash,
	requiredConfirmations uint,
	btcChain bitcoin.Chain,
	spvChain Chain,
) error

SubmitDepositSweepProof prepares deposit sweep proof for the given transaction and submits it to the on-chain contract. If the number of required confirmations is `0`, an error is returned.

func SubmitRedemptionProof

func SubmitRedemptionProof(
	transactionHash bitcoin.Hash,
	requiredConfirmations uint,
	btcChain bitcoin.Chain,
	spvChain Chain,
) error

SubmitRedemptionProof prepares redemption proof for the given transaction and submits it to the on-chain contract. If the number of required confirmations is `0`, an error is returned.

Types

type Chain

type Chain interface {
	// SubmitDepositSweepProofWithReimbursement submits the deposit sweep proof
	// via MaintainerProxy. It is used to prove the deposit sweep Bitcoin
	// transaction and update depositors' balances. The caller is reimbursed.
	SubmitDepositSweepProofWithReimbursement(
		transaction *bitcoin.Transaction,
		proof *bitcoin.SpvProof,
		mainUTXO bitcoin.UnspentTransactionOutput,
		vault common.Address,
	) error

	// GetDepositRequest gets the on-chain deposit request for the given
	// funding transaction hash and output index.The returned values represent:
	// - deposit request which is non-nil only when the deposit request was
	//   found,
	// - boolean value which is true if the deposit request was found, false
	//   otherwise,
	// - error which is non-nil only when the function execution failed. It will
	//   be nil if the deposit request was not found, but the function execution
	//   succeeded.
	GetDepositRequest(
		fundingTxHash bitcoin.Hash,
		fundingOutputIndex uint32,
	) (*tbtc.DepositChainRequest, bool, error)

	GetWallet(
		walletPublicKeyHash [20]byte,
	) (*tbtc.WalletChainData, error)

	// ComputeMainUtxoHash computes the hash of the provided main UTXO
	// according to the on-chain Bridge rules.
	ComputeMainUtxoHash(mainUtxo *bitcoin.UnspentTransactionOutput) [32]byte

	// TxProofDifficultyFactor returns the number of confirmations on the
	// Bitcoin chain required to successfully evaluate an SPV proof.
	TxProofDifficultyFactor() (*big.Int, error)

	// BlockCounter returns the chain's block counter.
	BlockCounter() (chain.BlockCounter, error)

	// GetPendingRedemptionRequest gets the on-chain pending redemption request
	// for the given wallet public key hash and redeemer output script.
	// The returned bool value indicates whether the request was found or not.
	GetPendingRedemptionRequest(
		walletPublicKeyHash [20]byte,
		redeemerOutputScript bitcoin.Script,
	) (*tbtc.RedemptionRequest, bool, error)

	// SubmitRedemptionProofWithReimbursement submits the redemption proof
	// via MaintainerProxy. The caller is reimbursed.
	SubmitRedemptionProofWithReimbursement(
		transaction *bitcoin.Transaction,
		proof *bitcoin.SpvProof,
		mainUTXO bitcoin.UnspentTransactionOutput,
		walletPublicKeyHash [20]byte,
	) error

	// PastDepositRevealedEvents fetches past deposit reveal events according
	// to the provided filter or unfiltered if the filter is nil. Returned
	// events are sorted by the block number in the ascending order, i.e. the
	// latest event is at the end of the slice.
	PastDepositRevealedEvents(
		filter *tbtc.DepositRevealedEventFilter,
	) ([]*tbtc.DepositRevealedEvent, error)

	// PastRedemptionRequestedEvents fetches past redemption requested events according
	// to the provided filter or unfiltered if the filter is nil. Returned
	// events are sorted by the block number in the ascending order, i.e. the
	// latest event is at the end of the slice.
	PastRedemptionRequestedEvents(
		filter *tbtc.RedemptionRequestedEventFilter,
	) ([]*tbtc.RedemptionRequestedEvent, error)
}

type Config

type Config struct {
	// Enabled indicates whether the SPV maintainer should be started.
	Enabled bool

	// HistoryDepth is the number of blocks to look back from the current block
	// when searching for past wallet-related events. To find Bitcoin transactions
	// for which the SPV proof should be submitted, the maintainer first inspects
	// the appropriate type of wallet-related events. This depth determines how
	// far into the past the system will consider events for processing. This
	// value must not be too high so that the event lookup is efficient. At the
	// same time, this value can not be too low to make sure all performed and
	// not yet proven transactions can be found.
	HistoryDepth uint64

	// TransactionLimit sets the maximum number of confirmed transactions
	// returned when getting transactions for a public key hash. Once the
	// maintainer establishes the list of wallets, it needs to check Bitcoin
	// transactions executed by each wallet. Then, it tries to find the
	// transactions matching the given proposal type. For example, if set
	// to `20`, only the latest twenty transactions will be returned. This
	// value must not be too high so that the transaction lookup is efficient.
	// At the same time, this value can not be too low to make sure the
	// performed proposal's transaction can be found in case the wallet decided
	// to execute some other Bitcoin transaction after the yet-not-proven
	// transaction.
	TransactionLimit int

	// RestartBackoffTime is a restart backoff which should be applied when the
	// SPV maintainer is restarted. It helps to avoid being flooded with error
	// logs in case of a permanent error in the SPV maintainer.
	RestartBackoffTime time.Duration

	// IdleBackoffTime is a wait time which should be applied when there are no
	// more transaction proofs to submit.
	IdleBackoffTime time.Duration
}

Config holds configurable properties.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL