Documentation
¶
Overview ¶
SECURITY: The calling code is responsible for handling mutex operations when working with this package.
Index ¶
- Constants
- Variables
- func IsPendingMsg(keyBytes []byte) bool
- func IsTransfer(keyBytes []byte) bool
- func PendingMsgID(k *common.MessagePublication) []byte
- func TransferMsgID(t *Transfer) []byte
- type AccountantDB
- type AggregatedTransaction
- type DBError
- type Database
- func (d *Database) AcctDeletePendingTransfer(msgId string) error
- func (d *Database) AcctGetData(logger *zap.Logger) ([]*common.MessagePublication, error)
- func (d *Database) AcctStorePendingTransfer(msg *common.MessagePublication) error
- func (d *Database) Close() error
- func (d *Database) Conn() *badger.DB
- func (d *Database) DeletePendingMsg(pending *PendingTransfer) error
- func (d *Database) DeleteTransfer(t *Transfer) error
- func (d *Database) FindEmitterSequenceGap(prefix VAAID) (resp []uint64, firstSeq uint64, lastSeq uint64, err error)
- func (d *Database) GetChainGovernorData(logger *zap.Logger) (transfers []*Transfer, pending []*PendingTransfer, err error)
- func (d *Database) GetChainGovernorDataForTime(logger *zap.Logger, now time.Time) (transfers []*Transfer, pending []*PendingTransfer, err error)
- func (d *Database) GetSignedVAABytes(id VAAID) (b []byte, err error)
- func (d *Database) HasVAA(id VAAID) (bool, error)
- func (d *Database) PurgeVaas(prefix VAAID, oldestTime time.Time, logOnly bool) (string, error)
- func (d *Database) StorePendingMsg(pending *PendingTransfer) error
- func (d *Database) StoreSignedVAA(v *vaa.VAA) error
- func (d *Database) StoreSignedVAABatch(vaaBatch []*vaa.VAA) error
- func (d *Database) StoreTransfer(t *Transfer) error
- type GovernorDB
- type ManagerDB
- func (d *ManagerDB) DeleteAggregatedTransaction(vaaHashHex string) error
- func (d *ManagerDB) GetAggregatedTransaction(vaaHashHex string) (*AggregatedTransaction, error)
- func (d *ManagerDB) GetAggregatedTransactionByVAAID(vaaID string) (*AggregatedTransaction, error)
- func (d *ManagerDB) HasAggregatedTransaction(vaaHashHex string) (bool, error)
- func (d *ManagerDB) LoadAllAggregatedTransactions() (map[string]*AggregatedTransaction, error)
- func (d *ManagerDB) StoreAggregatedTransaction(vaaHashHex string, tx *AggregatedTransaction) error
- type MockAccountantDB
- type MockGovernorDB
- func (d *MockGovernorDB) DeletePendingMsg(pending *PendingTransfer) error
- func (d *MockGovernorDB) DeleteTransfer(t *Transfer) error
- func (d *MockGovernorDB) GetChainGovernorData(logger *zap.Logger) (transfers []*Transfer, pending []*PendingTransfer, err error)
- func (d *MockGovernorDB) StorePendingMsg(k *PendingTransfer) error
- func (d *MockGovernorDB) StoreTransfer(t *Transfer) error
- type NotaryDB
- func (d *NotaryDB) DeleteBlackholed(msgID []byte) (*common.MessagePublication, error)
- func (d *NotaryDB) DeleteDelayed(msgID []byte) (*common.PendingMessage, error)
- func (d *NotaryDB) LoadAll(logger *zap.Logger) (*NotaryLoadResult, error)
- func (d *NotaryDB) StoreBlackholed(m *common.MessagePublication) error
- func (d *NotaryDB) StoreDelayed(p *common.PendingMessage) error
- type NotaryDBInterface
- type NotaryLoadResult
- type OldMessagePublication
- type Operation
- type PendingTransfer
- type Transfer
- type VAAID
Constants ¶
const ( Unknown dataType = "unknown" Delayed dataType = "delayed" Blackholed dataType = "blackholed" )
const ( // ScaledValueFactor is used to scale up the USD value to effectively increase rounding precision. // A uint64 can still represent dollar values up to 184 trillion with this scaling factor. // And for flow cancel we can represent up to 92 trillion dollars since we use int64. ScaledValueFactor = 100_000 )
These constants are used when the message format changes. It allows the governor to support both formats. This is important because when the message format changes and the Guardians are restarted, the existing messages will be stored in the old format. Both message formats need to be supported for duration of the Governor's sliding window.
Variables ¶
var ( ErrMarshal = errors.New("notary: marshal") ErrUnmarshal = errors.New("notary: unmarshal") )
var (
ErrManagerSigNotFound = errors.New("manager signature not found in store")
)
var (
ErrVAANotFound = errors.New("requested VAA not found in store")
)
Functions ¶
func IsPendingMsg ¶
func IsTransfer ¶
func PendingMsgID ¶
func PendingMsgID(k *common.MessagePublication) []byte
func TransferMsgID ¶
Types ¶
type AccountantDB ¶
type AccountantDB interface {
AcctStorePendingTransfer(msg *common.MessagePublication) error
AcctDeletePendingTransfer(msgId string) error
AcctGetData(logger *zap.Logger) ([]*common.MessagePublication, error)
}
type AggregatedTransaction ¶
type AggregatedTransaction struct {
// VAAHash is the hash of the VAA that triggered this signing.
VAAHash []byte
// VAAID is the VAA ID in format "{chain}/{emitter}/{sequence}".
VAAID string
// DestinationChain is the target chain (e.g., Dogecoin).
DestinationChain vaa.ChainID
// ManagerSetIndex is the delegated manager set index from the payload.
ManagerSetIndex uint32
// Required is the M value (number of signatures needed).
Required uint8
// Total is the N value (total number of possible signers).
Total uint8
// Signatures maps signer index to their signatures.
// Each entry contains the per-input signatures from that signer.
Signatures map[uint8][][]byte
}
AggregatedTransaction holds signatures from multiple signers for a single VAA. It is used to collect signatures until we have M-of-N required for broadcast.
func (*AggregatedTransaction) IsComplete ¶
func (a *AggregatedTransaction) IsComplete() bool
IsComplete returns true if this aggregated transaction has enough signatures.
func (*AggregatedTransaction) MarshalBinary ¶
func (s *AggregatedTransaction) MarshalBinary() ([]byte, error)
MarshalBinary serializes an AggregatedTransaction to bytes.
func (*AggregatedTransaction) UnmarshalBinary ¶
func (s *AggregatedTransaction) UnmarshalBinary(data []byte) error
UnmarshalBinary deserializes an AggregatedTransaction from bytes.
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
func (*Database) AcctDeletePendingTransfer ¶
func (*Database) AcctGetData ¶
This is called by the accountant on start up to reload pending transfers.
func (*Database) AcctStorePendingTransfer ¶
func (d *Database) AcctStorePendingTransfer(msg *common.MessagePublication) error
func (*Database) DeletePendingMsg ¶
func (d *Database) DeletePendingMsg(pending *PendingTransfer) error
This is called by the chain governor to delete a pending transfer.
func (*Database) DeleteTransfer ¶
This is called by the chain governor to delete a transfer after the time limit has expired.
func (*Database) FindEmitterSequenceGap ¶
func (*Database) GetChainGovernorData ¶
func (d *Database) GetChainGovernorData(logger *zap.Logger) (transfers []*Transfer, pending []*PendingTransfer, err error)
This is called by the chain governor on start up to reload status.
func (*Database) GetChainGovernorDataForTime ¶
func (*Database) GetSignedVAABytes ¶
func (*Database) StorePendingMsg ¶
func (d *Database) StorePendingMsg(pending *PendingTransfer) error
This is called by the chain governor to persist a pending transfer.
func (*Database) StoreSignedVAABatch ¶
StoreSignedVAABatch writes multiple VAAs to the database using the BadgerDB batch API. Note that the API takes care of splitting up the slice into the maximum allowed count and size so we don't need to worry about that.
func (*Database) StoreTransfer ¶
This is called by the chain governor to persist a pending transfer.
type GovernorDB ¶
type GovernorDB interface {
StoreTransfer(t *Transfer) error
StorePendingMsg(k *PendingTransfer) error
DeleteTransfer(t *Transfer) error
DeletePendingMsg(k *PendingTransfer) error
GetChainGovernorData(logger *zap.Logger) (transfers []*Transfer, pending []*PendingTransfer, err error)
}
type ManagerDB ¶
type ManagerDB struct {
// contains filtered or unexported fields
}
ManagerDB is a wrapper for the database connection used by the manager service. It provides methods for storing and retrieving aggregated manager signatures.
func NewManagerDB ¶
NewManagerDB creates a new ManagerDB instance.
func (*ManagerDB) DeleteAggregatedTransaction ¶
DeleteAggregatedTransaction removes an aggregated transaction from the database.
func (*ManagerDB) GetAggregatedTransaction ¶
func (d *ManagerDB) GetAggregatedTransaction(vaaHashHex string) (*AggregatedTransaction, error)
GetAggregatedTransaction retrieves an aggregated transaction from the database.
func (*ManagerDB) GetAggregatedTransactionByVAAID ¶
func (d *ManagerDB) GetAggregatedTransactionByVAAID(vaaID string) (*AggregatedTransaction, error)
GetAggregatedTransactionByVAAID retrieves an aggregated transaction by VAA ID using the index. This is O(1) lookup using the VAA ID -> hash index.
func (*ManagerDB) HasAggregatedTransaction ¶
HasAggregatedTransaction checks if an aggregated transaction exists in the database.
func (*ManagerDB) LoadAllAggregatedTransactions ¶
func (d *ManagerDB) LoadAllAggregatedTransactions() (map[string]*AggregatedTransaction, error)
LoadAllAggregatedTransactions loads all aggregated transactions from the database. This is useful for restoring state after a restart.
func (*ManagerDB) StoreAggregatedTransaction ¶
func (d *ManagerDB) StoreAggregatedTransaction(vaaHashHex string, tx *AggregatedTransaction) error
StoreAggregatedTransaction stores an aggregated transaction in the database.
type MockAccountantDB ¶
type MockAccountantDB struct {
}
func (*MockAccountantDB) AcctDeletePendingTransfer ¶
func (d *MockAccountantDB) AcctDeletePendingTransfer(msgId string) error
func (*MockAccountantDB) AcctGetData ¶
func (d *MockAccountantDB) AcctGetData(logger *zap.Logger) ([]*common.MessagePublication, error)
func (*MockAccountantDB) AcctStorePendingTransfer ¶
func (d *MockAccountantDB) AcctStorePendingTransfer(msg *common.MessagePublication) error
type MockGovernorDB ¶
type MockGovernorDB struct {
}
func (*MockGovernorDB) DeletePendingMsg ¶
func (d *MockGovernorDB) DeletePendingMsg(pending *PendingTransfer) error
func (*MockGovernorDB) DeleteTransfer ¶
func (d *MockGovernorDB) DeleteTransfer(t *Transfer) error
func (*MockGovernorDB) GetChainGovernorData ¶
func (d *MockGovernorDB) GetChainGovernorData(logger *zap.Logger) (transfers []*Transfer, pending []*PendingTransfer, err error)
func (*MockGovernorDB) StorePendingMsg ¶
func (d *MockGovernorDB) StorePendingMsg(k *PendingTransfer) error
func (*MockGovernorDB) StoreTransfer ¶
func (d *MockGovernorDB) StoreTransfer(t *Transfer) error
type NotaryDB ¶
type NotaryDB struct {
// contains filtered or unexported fields
}
NotaryDB is a wrapper struct for a database connection. Its main purpose is to provide some separation from the Notary's functionality and the general functioning of db.Database
func NewNotaryDB ¶
func (*NotaryDB) DeleteBlackholed ¶
func (d *NotaryDB) DeleteBlackholed(msgID []byte) (*common.MessagePublication, error)
DeleteBlackholed deletes a blackholed message from the database and returns the value that was deleted.
func (*NotaryDB) DeleteDelayed ¶
func (d *NotaryDB) DeleteDelayed(msgID []byte) (*common.PendingMessage, error)
DeleteDelayed deletes a delayed message from the database and returns the value that was deleted.
func (*NotaryDB) LoadAll ¶
func (d *NotaryDB) LoadAll(logger *zap.Logger) (*NotaryLoadResult, error)
LoadAll retrieves all keys from the database.
func (*NotaryDB) StoreBlackholed ¶
func (d *NotaryDB) StoreBlackholed(m *common.MessagePublication) error
func (*NotaryDB) StoreDelayed ¶
func (d *NotaryDB) StoreDelayed(p *common.PendingMessage) error
type NotaryDBInterface ¶
type NotaryDBInterface interface {
StoreBlackholed(m *common.MessagePublication) error
StoreDelayed(p *common.PendingMessage) error
DeleteBlackholed(msgID []byte) (*common.MessagePublication, error)
DeleteDelayed(msgID []byte) (*common.PendingMessage, error)
LoadAll(logger *zap.Logger) (*NotaryLoadResult, error)
}
type NotaryLoadResult ¶
type NotaryLoadResult struct {
Delayed []*common.PendingMessage
Blackholed []*common.MessagePublication
}
type OldMessagePublication ¶
type OldMessagePublication struct {
TxHash ethCommon.Hash
Timestamp time.Time
Nonce uint32
Sequence uint64
ConsistencyLevel uint8
EmitterChain vaa.ChainID
EmitterAddress vaa.Address
Payload []byte
IsReobservation bool
Unreliable bool
}
OldMessagePublication is used to unmarshal old JSON which has the TxHash rather than the TxID.
func (*OldMessagePublication) UnmarshalJSON ¶
func (msg *OldMessagePublication) UnmarshalJSON(data []byte) error
type PendingTransfer ¶
type PendingTransfer struct {
ReleaseTime time.Time
Msg common.MessagePublication
}
PendingTransfer represent a pending transfer that is waiting to be released by the Governor. It is the same as a common.MessagePublication, but with a timestamp indicating when it can be released. Upon release, it is converted to a Transfer. It is also referred to as a "pending message" in the codebase.
func UnmarshalPendingTransfer ¶
func UnmarshalPendingTransfer(data []byte, isOld bool) (*PendingTransfer, error)
UnmarshalPendingTransfer deserializes a PendingTransfer. TODO: This function could be rewritten to use the BinaryUnmarshaler interface.
func (*PendingTransfer) Marshal ¶
func (p *PendingTransfer) Marshal() ([]byte, error)
Marshal returns the pending transfer serialized. TODO: This function could be rewritten to use the BinaryMarshaler interface.
type Transfer ¶
type Transfer struct {
// This value is generated by the Governor. It is not read from the blockchain transaction. It represents the
// time at which it was observed and evaluated by the Governor.
Timestamp time.Time
// Scaled by scaledValueFactor notional USD value of the transfer
ScaledValue uint64
// Where the asset was minted
OriginChain vaa.ChainID
OriginAddress vaa.Address
// Where the transfer was emitted. Not necessarily equal to OriginChain
EmitterChain vaa.ChainID
EmitterAddress vaa.Address
MsgID string
Hash string
TargetAddress vaa.Address
TargetChain vaa.ChainID
}
Transfer represents a completed transfer that has been processed by the Governor during its sliding window.
func UnmarshalTransfer ¶
UnmarshalTransfer deserializes a Transfer. TODO: This function could be rewritten to use the BinaryUnmarshaler interface.
type VAAID ¶
func VaaIDFromString ¶
VaaIDFromString parses a <chain>/<address>/<sequence> string into a VAAID.