btcdiff

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: 7 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Initialize

func Initialize(
	ctx context.Context,
	config Config,
	btcChain bitcoin.Chain,
	chain Chain,
)

Types

type Chain

type Chain interface {
	// Ready checks whether the relay is active (i.e. genesis has been performed).
	// Note that if the relay is used by querying the current and previous epoch
	// difficulty, at least one retarget needs to be provided after genesis;
	// otherwise the prevEpochDifficulty will be uninitialized and zero.
	Ready() (bool, error)

	// IsAuthorized checks whether the given address has been authorized to
	// submit a retarget directly to LightRelay. This function should be used
	// when retargetting via LightRelayMaintainerProxy is disabled.
	IsAuthorized(address chain.Address) (bool, error)

	// IsAuthorizedForRefund checks whether the given address has been
	// authorized to submit a retarget via LightRelayMaintainerProxy. This
	// function should be used when retargetting via LightRelayMaintainerProxy
	// is not disabled.
	IsAuthorizedForRefund(address chain.Address) (bool, error)

	// Signing returns the signing associated with the chain.
	Signing() chain.Signing

	// Retarget adds a new epoch to the relay by providing a proof of the
	// difficulty before and after the retarget. The cost of calling this
	// function is not refunded to the caller.
	Retarget(headers []*bitcoin.BlockHeader) error

	// RetargetWithRefund adds a new epoch to the relay by providing a proof of
	// the difficulty before and after the retarget. The cost of calling this
	// function is refunded to the caller.
	RetargetWithRefund(headers []*bitcoin.BlockHeader) error

	// CurrentEpoch returns the number of the latest difficulty epoch which is
	// proven to the relay. If the genesis epoch's number is set correctly, and
	// retargets along the way have been legitimate, this equals the height of
	// the block starting the most recent epoch, divided by 2016.
	CurrentEpoch() (uint64, error)

	// ProofLength returns the number of blocks required for each side of a
	// retarget proof.
	ProofLength() (uint64, error)

	// GetCurrentAndPrevEpochDifficulty returns the difficulties of the current
	// and previous Bitcoin epochs.
	GetCurrentAndPrevEpochDifficulty() (*big.Int, *big.Int, error)
}

Chain is an interface that provides the ability to communicate with the Bitcoin difficulty on-chain contract.

type Config

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

	// DisableProxy indicates whether the Bitcoin difficulty
	// maintainer proxy should be disabled. By default, the Bitcoin difficulty
	// maintainer submits the epoch headers to the relay via the proxy to be
	// reimbursed for the transaction. If this option is set to true, the epoch
	// headers will be submitted directly to the relay.
	DisableProxy bool

	// IdleBackOffTime is a wait time which should be applied when there are no
	// more Bitcoin epochs to be proven because the difficulty maintainer is
	// up-to-date with the Bitcoin blockchain or there are not enough blocks yet
	// to prove the new epoch.
	IdleBackOffTime time.Duration

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

Config contains maintainer configuration.

Jump to

Keyboard shortcuts

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