Documentation
¶
Overview ¶
Package delegateprofile bridges the on-chain DelegateProfile contract into the IIP-59 protocol-native voter reward path.
PutPollResult calls the bridge once per epoch, passing the freshly selected candidate list. The bridge issues two view calls per delegate against the DelegateProfile contract (getProfileByField for "blockRewardPortion" and "epochRewardPortion") and returns the per-delegate commission split in basis points. Downstream (PR 2') freezes those values into the poll snapshot; rewarding (PR 3'/4') consumes them at epoch close.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrRateOutOfRange is returned when the on-chain field decodes to a value // outside [0, 10000]. Callers should treat this as a hard error at // PutPollResult — a malformed profile must not be silently ignored, since // silently defaulting to 0% would flip the delegate's whole reward stream // to the wrong party. ErrRateOutOfRange = errors.New("delegateprofile: portion out of range [0, 10000]") // ErrEmptyContractAddress is returned when the bridge is constructed // without a target contract. ErrEmptyContractAddress = errors.New("delegateprofile: empty contract address") )
Functions ¶
This section is empty.
Types ¶
type Bridge ¶
type Bridge struct {
// contains filtered or unexported fields
}
Bridge is the reusable read-only wrapper around a specific DelegateProfile contract deployment. Construct once at protocol init with the network's fixed contract address; call Snapshot once per PutPollResult.
func New ¶
New constructs a Bridge targeting contract. contract must be a valid IoTeX bech32 address; the caller is responsible for pinning it to the network-appropriate mainnet/testnet value.
func (*Bridge) Snapshot ¶
func (b *Bridge) Snapshot( ctx context.Context, reader ContractReader, delegates []address.Address, ) (map[string]*CommissionRates, error)
Snapshot reads commission portions for each delegate and returns a map keyed by delegate identity string (bech32). The map always contains one entry per input delegate.
Reads run sequentially in `delegates` order, so per-epoch behaviour is deterministic and matches the caller's PutPollResult ordering.
A per-delegate read error is logged and represented as Configured=false; rewarding then applies the full-owner commission fallback. This keeps one malformed profile from blocking the entire era snapshot.
Only wiring bugs — nil reader, nil delegate address — return an error.
type CommissionRates ¶
type CommissionRates struct {
// BlockCommissionBasisPoints is the delegate's take of the block-reward
// stream, in basis points [0, 10000]. Derived as 10000 - voterTake_bp,
// where voterTake_bp is the raw uint64 stored on-chain under
// "blockRewardPortion".
BlockCommissionBasisPoints uint64
// EpochCommissionBasisPoints is the delegate's take of the epoch-reward
// stream, in basis points [0, 10000]. Derived from "epochRewardPortion".
EpochCommissionBasisPoints uint64
// Configured is true iff both portion fields returned non-empty valid bytes.
// A partial profile (one field set, the other empty) is treated as
// Configured=false and therefore uses the all-to-owner default.
Configured bool
}
CommissionRates carries the per-delegate result of a single bridge lookup.
Configured flags whether DelegateProfile has both reward portion fields set to valid values for this delegate. It is deliberately unrelated to the legacy DelegateProfile.registered(address) view, which is not reliable for the deployed mainnet contract. The snapshot consumer ignores both rates when Configured is false and applies the all-to-delegate fallback.
type ContractReader ¶
type ContractReader interface {
Read(ctx context.Context, contract string, callData []byte) ([]byte, error)
}
ContractReader is the read-only view call primitive the bridge depends on. PutPollResult supplies an adapter around evm.SimulateExecution; tests supply an in-memory fake. The bridge does not depend on protocol.StateManager directly so it stays trivially unit-testable.
type ContractReaderFunc ¶
ContractReaderFunc lets a plain function satisfy ContractReader.