Documentation
¶
Overview ¶
Package simnode simulates the Akash and Solana nodes the reporter reads, serving a Scenario over the nodes' own protocols for integration tests, goldens and benchmarks.
Index ¶
- Constants
- Variables
- func EncodeBridgeConfig(c BridgeConfig) []byte
- func EncodeLaunchConfig(c LaunchConfig) []byte
- func EncodeMint(m Mint) []byte
- func EncodeTransferResolved(s TransferStatus) []byte
- func EncodeTransferStatus(s TransferStatus) []byte
- func Goldens() []string
- func Scenarios() map[string]func() Scenario
- func TransferResolvedLog(s TransferStatus) string
- func TxConfig() client.TxConfig
- type Account
- type AccountChange
- type AddressTableLookup
- type Akash
- type AuthAccount
- type Block
- type BridgeConfig
- type BroadcastFault
- type Delivery
- type Failure
- type FaultKind
- type Header
- type LaunchConfig
- type Mint
- type Minted
- type Node
- func (n *Node) Broadcasts() [][]byte
- func (n *Node) Calls(method string) int
- func (n *Node) Close()
- func (n *Node) CommitBlock()
- func (n *Node) Executions() map[string]int
- func (n *Node) Gossip(txBytes []byte)
- func (n *Node) Halt()
- func (n *Node) Mutate(f func(*Scenario))
- func (n *Node) Resolve(id sinkid.ID, status sinkv1.Status, evidence ...sinkv1.Observation)
- func (n *Node) SetLag(blocks int64)
- type Options
- type Outcome
- type Scenario
- type SimFailure
- type SinkState
- type Solana
- type Transaction
- type Transfer
- type TransferStatus
- type VoidReason
Constants ¶
const ( ChainID = "simnode-1" // GenesisHash is Solana devnet's. GenesisHash = "EtWTRABZaYq6iMfeYKouRu166VU2xqa1wcaWoxPkrZBG" // ReporterMnemonic derives Reporter on akash's HD path m/44'/118'/0'/0/0. ReporterMnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon " + "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon art" // ReporterMaxAge is the max-age the goldens configure their reporters with, the reporter's default. ReporterMaxAge = 60 * time.Second )
The identities every named scenario shares, for configuring a reporter against it. None is a mainnet identity.
Variables ¶
var ( ProgramID = seedKey("program") LightClient = seedKey("light-client") MintAddress = aktsolana.PDA(ProgramID, []byte("mint")) // Reporter is the policy member whose key ReporterMnemonic derives. Reporter = reporterAddress() )
Functions ¶
func EncodeBridgeConfig ¶
func EncodeBridgeConfig(c BridgeConfig) []byte
EncodeBridgeConfig returns BridgeConfig account data, padded to its allocated size.
func EncodeLaunchConfig ¶
func EncodeLaunchConfig(c LaunchConfig) []byte
EncodeLaunchConfig returns LaunchConfig account data, padded to its allocated size.
func EncodeTransferResolved ¶
func EncodeTransferResolved(s TransferStatus) []byte
EncodeTransferResolved returns the Anchor event data of TransferResolved, discriminator included.
func EncodeTransferStatus ¶
func EncodeTransferStatus(s TransferStatus) []byte
EncodeTransferStatus returns TransferStatus account data, padded to its allocated size.
func Goldens ¶
func Goldens() []string
Goldens returns the sorted names of the scenarios that have a parity golden: every scenario but the benchmarks.
func Scenarios ¶
Scenarios returns the named scenarios that goldens and benchmarks serve, each built fresh by its function. The comment of each golden scenario names the parity cases of spec §11.2 it covers.
func TransferResolvedLog ¶
func TransferResolvedLog(s TransferStatus) string
TransferResolvedLog returns the "Program data:" log line that emit! writes for the event.
Types ¶
type Account ¶
type Account struct {
Owner solana.PublicKey `json:"owner"`
Executable bool `json:"executable,omitempty"`
Lamports uint64 `json:"lamports,omitempty"`
Data []byte `json:"data,omitempty"`
}
Account is an account as the finalized bank holds it.
type AccountChange ¶
type AccountChange struct {
AfterCalls int `json:"afterCalls"`
Slot uint64 `json:"slot,omitempty"`
Accounts map[solana.PublicKey]Account `json:"accounts,omitempty"`
}
AccountChange replaces accounts, and the finalized slot when Slot is non-zero, after AfterCalls getMultipleAccounts calls.
type AddressTableLookup ¶
type AddressTableLookup struct {
AccountKey solana.PublicKey `json:"accountKey"`
WritableIndexes []int `json:"writableIndexes"`
ReadonlyIndexes []int `json:"readonlyIndexes"`
}
AddressTableLookup is a v0 message's reference to an address lookup table.
type Akash ¶
type Akash struct {
ChainID string `json:"chainId"`
// NodeID is the CometBFT node ID in hex, reported by status and GetNodeInfo.
NodeID string `json:"nodeId"`
// NoTxIndex reports tx_index "off", and tx then fails as on a node without an index.
NoTxIndex bool `json:"noTxIndex,omitempty"`
CatchingUp bool `json:"catchingUp,omitempty"`
// IndexLag keeps the transaction and block indexes that many blocks below the served height, as CometBFT indexes a
// block only after committing it: tx, tx_search and block_search find nothing above.
IndexLag int64 `json:"indexLag,omitempty"`
// TxIndexBehind keeps the transaction index one block below the block index, as between CometBFT indexing a block's
// events and writing its transactions.
TxIndexBehind bool `json:"txIndexBehind,omitempty"`
// RefuseBatches answers a JSON-RPC batch with a single error, as a gateway without batch support does.
RefuseBatches bool `json:"refuseBatches,omitempty"`
// ReverseBatches answers a JSON-RPC batch with its responses in reverse order, which JSON-RPC allows.
ReverseBatches bool `json:"reverseBatches,omitempty"`
// Height is the latest block. BlockTimes holds each block's time; its lowest key is the earliest retained height,
// and state below it is pruned.
Height int64 `json:"height"`
BlockTimes map[int64]time.Duration `json:"blockTimes,omitempty"`
// AppHeight is the application's last committed height when it trails Height; zero means Height. Committed blocks
// keep the gap.
AppHeight int64 `json:"appHeight,omitempty"`
// EchoOffset is added to the height that query answers repeat, to serve a node that answers another height.
EchoOffset int64 `json:"echoOffset,omitempty"`
// PageOverlap serves an inconsistent pagination: a full page's next key resumes at its own last entry, so the next
// page repeats it.
PageOverlap bool `json:"pageOverlap,omitempty"`
// FailHistory lists the ordinals, from 1, of the chronological history walks (Transfers without a status or owner
// filter, over gRPC or abci_query) that fail with codes.Unavailable.
FailHistory []int `json:"failHistory,omitempty"`
Params sinkv1.Params `json:"params"`
// Policies holds every retained reporter policy; the highest version is current.
Policies []sinkv1.ReporterPolicy `json:"policies,omitempty"`
State SinkState `json:"state"`
// Transfers holds every version of every transfer. A version applies from its Height until the next version of
// the same ID; executed messages append versions.
Transfers []Transfer `json:"transfers,omitempty"`
Accounts []AuthAccount `json:"accounts,omitempty"`
// Usage is each owner's sink account usage, served by the sink Account query.
Usage map[string]sinkv1.AccountUsage `json:"usage,omitempty"`
// SimFailures fail matching messages in Simulate, at their message index.
SimFailures []SimFailure `json:"simFailures,omitempty"`
// BroadcastFaults are consumed one per broadcast_tx_sync attempt, in order.
BroadcastFaults []BroadcastFault `json:"broadcastFaults,omitempty"`
// UnorderedDisabled refuses every transaction as a chain without unordered transactions does.
UnorderedDisabled bool `json:"unorderedDisabled,omitempty"`
// BlockMaxGas is the consensus block max gas that cosmos.consensus.v1.Query/Params serves; zero serves -1,
// unlimited. When positive, the ante checks refuse a transaction declaring more gas, in simulation too
// (x/auth/ante/setup.go).
BlockMaxGas int64 `json:"blockMaxGas,omitempty"`
// Deliveries are consumed one per executed transaction, in block order; a non-zero Code fails that transaction
// after its replay key is stored, so it pays its fee and changes nothing.
Deliveries []Delivery `json:"deliveries,omitempty"`
}
Akash is the state of the Akash chain and of the node serving it. Every time in it is an offset from Start.
type AuthAccount ¶
type AuthAccount struct {
Address string `json:"address"`
Number uint64 `json:"number"`
PubKey []byte `json:"pubKey,omitempty"`
}
AuthAccount is a base account; PubKey is a compressed secp256k1 key, absent before the account signs.
type Block ¶
type Block struct {
Transactions []Transaction `json:"transactions"`
}
Block is a confirmed block. Its hashes and parent are derived from its slot; its time comes from BlockTimes.
type BridgeConfig ¶
type BridgeConfig struct {
LightClientProgram solana.PublicKey
ChainID string
PerTransferMax uint64
DailyMintCap uint64
Vaults []solana.PublicKey
MintDay uint64
MintedToday uint64
}
BridgeConfig is the account at ["bridge"], MintPolicy flattened into it.
type BroadcastFault ¶
type BroadcastFault struct {
Kind FaultKind `json:"kind,omitempty"`
Code uint32 `json:"code,omitempty"`
Codespace string `json:"codespace,omitempty"`
Log string `json:"log,omitempty"`
}
BroadcastFault is the outcome injected into one broadcast attempt.
type Delivery ¶
type Delivery struct {
Code uint32 `json:"code,omitempty"`
Codespace string `json:"codespace,omitempty"`
Log string `json:"log,omitempty"`
}
Delivery is the result injected into one executed transaction; Code zero lets it execute.
type Failure ¶
type Failure struct {
Code int `json:"code,omitempty"`
Message string `json:"message,omitempty"`
HTTPStatus int `json:"httpStatus,omitempty"`
// Times is how many calls fail before the failure is removed from the scenario; zero fails every call.
Times int `json:"times,omitempty"`
}
Failure makes a JSON-RPC method fail. A non-zero HTTPStatus answers with that status and no body; otherwise the method returns the JSON-RPC error Code and Message.
type FaultKind ¶
type FaultKind string
FaultKind is how a broadcast attempt goes wrong (spec §6.5).
const ( // FaultNone admits the attempt normally. FaultNone FaultKind = "" // FaultTransport drops the connection before admission. FaultTransport FaultKind = "transport" // FaultLostResponse admits the transaction, then drops the connection. FaultLostResponse FaultKind = "lost-response" // FaultInCache answers the JSON-RPC error "tx already exists in cache". FaultInCache FaultKind = "in-cache" // FaultNonceTaken refuses the transaction with "failed to add unordered nonce". FaultNonceTaken FaultKind = "nonce-taken" // FaultReject refuses the transaction in CheckTx with Code, Codespace and Log. FaultReject FaultKind = "reject" )
Broadcast faults.
type Header ¶
type Header struct {
NumRequiredSignatures int `json:"numRequiredSignatures"`
NumReadonlySignedAccounts int `json:"numReadonlySignedAccounts"`
NumReadonlyUnsignedAccounts int `json:"numReadonlyUnsignedAccounts"`
}
Header is a message header.
type LaunchConfig ¶
type LaunchConfig struct {
Version uint8
Initializer solana.PublicKey
Mint solana.PublicKey
BridgeEnabled bool
InitializedAtSlot uint64
Bump uint8
MintAuthorityBump uint8
}
LaunchConfig is the account at ["config"].
type Mint ¶
type Mint struct {
MintAuthority *solana.PublicKey
Supply uint64
Decimals uint8
Initialized bool
FreezeAuthority *solana.PublicKey
}
Mint is an SPL Token mint; a nil authority is COption::None.
type Node ¶
type Node struct {
CometURL string
GRPCAddr string
SolanaURL string
// contains filtered or unexported fields
}
Node serves a Scenario on loopback listeners until Close.
func Start ¶
Start serves sc and returns once every listener is bound; ctx bounds only the start-up. Start takes ownership of sc: change it afterwards only through Mutate. The CometBFT and gRPC endpoints are served only when sc has an Akash part.
func (*Node) Broadcasts ¶
Broadcasts returns the bytes of every broadcast_tx_sync attempt, in order.
func (*Node) Calls ¶
Calls returns how many calls of method the node has received: a Solana or CometBFT JSON-RPC method name, or a gRPC full method name such as "/akash.sink.v1.Query/Transfer".
func (*Node) Close ¶
func (n *Node) Close()
Close stops every server and drops open connections. It is safe to call more than once.
func (*Node) CommitBlock ¶
func (n *Node) CommitBlock()
CommitBlock produces the next block from every pending transaction and advances the height and time (spec §2.2).
func (*Node) Executions ¶
Executions counts the code-0 executions of each message key (spec §6.1), duplicate no-ops included: "<type URL>|<id>|<outcome>|<round>|<policy version>" for a vote, "<type URL>|<id>|<round at execution>" for a veto and "<type URL>|<id>" for a refund.
func (*Node) Gossip ¶
Gossip adds a transaction to the pending pool without admission, as if another node had accepted it. It holds no replay key at this node's admission, so a copy can be admitted here and lose in the block. Bytes already pending or included are ignored.
func (*Node) Halt ¶
func (n *Node) Halt()
Halt stops block production: CommitBlock and the BlockInterval ticker do nothing afterwards. The node still admits transactions.
func (*Node) Mutate ¶
Mutate changes the served scenario under the node's lock; requests see either the old or the new state.
func (*Node) Resolve ¶
Resolve applies a governance resolution in a block of its own, as x/sink/keeper/settlement.go:296-362 does: a new round under the current policy, without votes, hold or veto, with status, and a new challenge window from the block's time when status is STATUS_REFUND_PENDING. A confirmation (STATUS_MINTED, or STATUS_REFUND_PENDING for a confirmed void) records the governance observation, with the slot and signature of evidence[0] when given; the restart statuses record none. Pending transactions stay pending. The block is produced even on a halted node. It panics on an unknown transfer, a test error.
type Options ¶
type Options struct {
// Clock is the time the scenario's offsets are rebased against at Start; it defaults to the system clock.
Clock clock.Clock
// AkashLatency delays every CometBFT and gRPC request.
AkashLatency time.Duration
// SolanaLatency delays every Solana request.
SolanaLatency time.Duration
// BlockFetchLatency further delays every getBlock request.
BlockFetchLatency time.Duration
// BlockInterval, when positive, commits an Akash block each time that much Clock time passes.
BlockInterval time.Duration
// AlignWindow rebases Akash time at Start so the latest block time lies in the first 60 s of a Unix-aligned
// 2-minute window and 0 to 70 s behind Clock.Now(). Block times then advance with the clock at that offset.
AlignWindow bool
}
Options configures a Node.
type Outcome ¶
type Outcome struct {
Minted *Minted
Voided *VoidReason
}
Outcome is the Borsh enum TransferOutcome. Set exactly one field; with neither, the encoding carries an invalid variant tag, so that a scenario can serve a corrupt outcome.
type Scenario ¶
type Scenario struct {
// Passes is how many passes the goldens run; zero means one. Read it through PassCount.
Passes int `json:"passes,omitempty"`
// LightClientPin configures the reporter the goldens run, not the chain: when set, that reporter pins this light
// client; otherwise it follows the bridge.
LightClientPin *solana.PublicKey `json:"lightClientPin,omitempty"`
// Akash is absent from a scenario that serves only Solana; the node then serves no CometBFT or gRPC endpoint.
Akash *Akash `json:"akash,omitempty"`
Solana Solana `json:"solana"`
}
Scenario is the chain state a Node serves. It round-trips through encoding/json. Every time in it is an offset from the moment Start runs, so the state is equally fresh whenever and wherever it is served.
func Steady100k ¶
func Steady100k() Scenario
Steady100k is the steady-100k benchmark workload of spec §11.4: 100,000 open transfers under a 3-member policy, after 100 settled transfers that make up the first audit page. Of the open transfers:
- 70,000 are transfer-pending without votes or a Solana status; they plan nothing and need no evidence;
- 20,000 transfer-pending, 4,000 refund-pending inside their challenge window and 1,000 held disputes are resolved on Solana with this reporter's matching vote stored, so its evidence is reused and no block is read; each dispute alerts for governance review;
- 5,000 are void-requested and voided on Solana without this reporter's vote, so each plans one MsgReportOutcome. Their resolutions are spread over 100 blocks of 1,500 transactions each.
type SimFailure ¶
type SimFailure struct {
ID string `json:"id"`
TypeURL string `json:"typeUrl,omitempty"`
Error string `json:"error"`
}
SimFailure fails, in Simulate, every message about transfer ID (canonical text) of TypeURL, or of any sink type when TypeURL is empty.
type SinkState ¶
type SinkState struct {
Totals sinkv1.Totals `json:"totals"`
Epoch uint64 `json:"epoch"`
SendUsage sinkv1.EpochUsage `json:"sendUsage"`
RefundUsage sinkv1.EpochUsage `json:"refundUsage"`
}
SinkState is the module state the State query serves; the refund head is derived from the transfers.
type Solana ¶
type Solana struct {
GenesisHash string `json:"genesisHash"`
// Slot is the finalized slot: the context slot of account reads and the newest block served.
Slot uint64 `json:"slot"`
// BlockTimes holds each slot's block time as an offset from start. getBlockTime answers null for other slots.
BlockTimes map[uint64]time.Duration `json:"blockTimes,omitempty"`
Accounts map[solana.PublicKey]Account `json:"accounts,omitempty"`
Blocks map[uint64]Block `json:"blocks,omitempty"`
Failures map[string]Failure `json:"failures,omitempty"`
// Changes apply in order, each before the first getMultipleAccounts call beyond its AfterCalls is served, as a
// finalized slot that moves on while a reporter reads.
Changes []AccountChange `json:"changes,omitempty"`
}
Solana is the finalized state of the Solana cluster.
type Transaction ¶
type Transaction struct {
// Signatures are base58 text; they are not checked, so a scenario can serve malformed ones.
Signatures []string `json:"signatures"`
// Version is "legacy" (also when empty) or a decimal version such as "0" or "1".
Version string `json:"version,omitempty"`
Header Header `json:"header"`
AccountKeys []solana.PublicKey `json:"accountKeys"`
// AddressTableLookups, LoadedWritable and LoadedReadonly describe a v0 message's lookup tables.
AddressTableLookups []AddressTableLookup `json:"addressTableLookups,omitempty"`
LoadedWritable []solana.PublicKey `json:"loadedWritable,omitempty"`
LoadedReadonly []solana.PublicKey `json:"loadedReadonly,omitempty"`
// Err is meta.err, a TransactionError in JSON; empty means success.
Err json.RawMessage `json:"err,omitempty"`
// Logs is meta.logMessages; nil serves null, as a node that recorded no logs does.
Logs []string `json:"logs"`
}
Transaction is a transaction as Agave's JSON encoding describes it.
type Transfer ¶
type Transfer struct {
Height int64 `json:"height,omitempty"`
Transfer sinkv1.TransferState `json:"transfer"`
}
Transfer is one version of a transfer, from Height on; zero means from the earliest height.
type TransferStatus ¶
type TransferStatus struct {
ID sinkid.ID
ProofHeight uint64
ResolvedAtSlot uint64
Outcome Outcome
}
TransferStatus is the account at ["transfer", SHA256(owner), LE64(height), LE64(sequence)], and the payload of the TransferResolved event.
type VoidReason ¶
type VoidReason uint8
VoidReason is the Borsh enum VoidReason.
const ( VoidInvalidRecipient VoidReason = iota VoidGovernance )
Void reasons in declaration order.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
simnode
command
Command simnode serves a named simnode scenario for processes outside Go tests: the TS parity goldens and the steady-100k benchmark.
|
Command simnode serves a named simnode scenario for processes outside Go tests: the TS parity goldens and the steady-100k benchmark. |