Documentation ¶
Overview ¶
Package state is designed to handle current synchronization state. It is basically here to help out with progress, re-syncing, knowing exactly what we downloaded at which time, so we can efficiently handle downloading and download resumption.
Index ¶
- type BlockEntry
- type Descriptor
- type Key
- type State
- func (s *State) Descriptor() *Descriptor
- func (s *State) Exists(ctx context.Context, key Key) (bool, error)
- func (s *State) Get(ctx context.Context, key Key) (*big.Int, error)
- func (s *State) GetBlockEntry(ctx context.Context, networkId utils.NetworkID, block *types.Block) (*BlockEntry, error)
- func (s *State) GetBlockKey(networkId utils.NetworkID, blockNumber *big.Int) Key
- func (s *State) GetLatestInspectedBlock(key Key) (*big.Int, error)
- func (s *State) IncrementBlock(entry *BlockEntry, direction Key, success bool, hashes ...common.Hash) error
- func (s *State) IsBlockCompleted(ctx context.Context, networkId utils.NetworkID, block *types.Block) (bool, error)
- func (s *State) Load() error
- func (s *State) Monitor(ctx context.Context) error
- func (s *State) Set(ctx context.Context, key Key, value *big.Int) error
- func (s *State) SetDescriptorKey(key Key, value any) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BlockEntry ¶
type BlockEntry struct { NetworkId utils.NetworkID `json:"networkId" msgpack:"networkId"` BlockNumber *big.Int `json:"blockNumber" msgpack:"blockNumber"` TotalTransactionsCount int `json:"totalTransactionsCount" msgpack:"totalTransactionsCount"` SuccessfulTransactionsCount int `json:"successfulTransactionsCount" msgpack:"successfulTransactionsCount"` FailedTransactionsCount int `json:"failedTransactionsCount" msgpack:"failedTransactionsCount"` FailedTransactions map[common.Hash]struct{} `json:"failedTransactions" msgpack:"failedTransactions"` }
func (*BlockEntry) MarshalBinary ¶
func (e *BlockEntry) MarshalBinary() ([]byte, error)
func (*BlockEntry) UnmarshalBinary ¶
func (e *BlockEntry) UnmarshalBinary(data []byte) error
type Descriptor ¶
type Key ¶
type Key string
Key defines a string type used for state keys within the application. It provides a method for easy conversion back to a native string type, facilitating interactions with external storage systems.
const ( CurrentBlockHead Key = "inspector:state:current-block-head-5" // CurrentBlockHead represents the current head of the blockchain. UnknownHeadBlock Key = "unknown-head-key" LatestInspectedHeadBlock Key = "inspector:state:latest-inspected-head-block-5" // LatestInspectedHeadBlock represents the latest head block that has been inspected by the application. LatestInspectedArchiveBlock Key = "inspector:state:latest-inspected-archive-block-5" // LatestInspectedArchiveBlock represents the latest archive block that has been inspected by the application. ArchiveStartBlockNumber Key = "inspector:state:archive-start-block-number-5" ArchiveEndBlockNumber Key = "inspector:state:archive-end-block-number-5" )
Predefined state keys for common blockchain-related values.
type State ¶
type State struct {
// contains filtered or unexported fields
}
State encapsulates the application's state with context awareness and caching capabilities. It integrates with a Redis cache to store arbitrary large numbers, commonly used for storing and retrieving blockchain-related numeric data.
func New ¶
New initializes a new State instance with a given context and cache. It returns a pointer to the created State and any error encountered during its creation.
func (*State) Descriptor ¶
func (s *State) Descriptor() *Descriptor
func (*State) Exists ¶
Exists checks for the existence of a key within the state cache. It returns a boolean indicating the presence of the key and any error encountered.
func (*State) Get ¶
Get retrieves a value based on a key from the state cache. It converts the byte slice response back into a big.Int for usage within the application.