Documentation ¶
Overview ¶
Package chainservice is a chain service responsible for submitting blockchain transactions and relaying blockchain events.
Index ¶
- Constants
- Variables
- func NewEventTracker(startBlock uint64) *eventTracker
- func SetupSimulatedBackend(numAccounts uint64) (SimulatedChain, Bindings, []*bind.TransactOpts, error)
- type AllocationUpdatedEvent
- type BackendWrapper
- type Bindings
- type ChainEventHandler
- type ChainOpts
- type ChainService
- type ChallengeRegisteredEvent
- func (ce ChallengeRegisteredEvent) BlockNum() uint64
- func (ce ChallengeRegisteredEvent) ChannelID() types.Destination
- func (cr ChallengeRegisteredEvent) Outcome() outcome.Exit
- func (cr ChallengeRegisteredEvent) SignedState(fp state.FixedPart) (state.SignedState, error)
- func (cr ChallengeRegisteredEvent) StateHash(fp state.FixedPart) (common.Hash, error)
- func (cr ChallengeRegisteredEvent) String() string
- func (ce ChallengeRegisteredEvent) TxIndex() uint
- type ConcludedEvent
- type DepositedEvent
- type EthChainService
- func (ecs *EthChainService) Close() error
- func (ecs *EthChainService) EventFeed() <-chan Event
- func (ecs *EthChainService) GetChainId() (*big.Int, error)
- func (ecs *EthChainService) GetConsensusAppAddress() types.Address
- func (ecs *EthChainService) GetLastConfirmedBlockNum() uint64
- func (ecs *EthChainService) GetVirtualPaymentAppAddress() types.Address
- func (ecs *EthChainService) SendTransaction(tx protocols.ChainTransaction) error
- type Event
- type MockChain
- type MockChainService
- func (mc *MockChainService) Close() error
- func (mc *MockChainService) EventFeed() <-chan Event
- func (mc *MockChainService) GetChainId() (*big.Int, error)
- func (mc *MockChainService) GetConsensusAppAddress() types.Address
- func (mc *MockChainService) GetLastConfirmedBlockNum() uint64
- func (mc *MockChainService) GetVirtualPaymentAppAddress() types.Address
- func (mc *MockChainService) SendTransaction(tx protocols.ChainTransaction) error
- type SimulatedBackendChainService
- type SimulatedChain
Constants ¶
const ( MIN_BACKOFF_TIME = 1 * time.Second MAX_BACKOFF_TIME = 5 * time.Minute )
const MAX_EPOCHS = 60480
MAX_EPOCHS is the maximum range of old epochs we can query with a single "FilterLogs" request This is a restriction enforced by the rpc provider
const MAX_QUERY_BLOCK_RANGE = 2000
MAX_QUERY_BLOCK_RANGE is the maximum range of blocks we query for events at once. Most json-rpc nodes restrict the amount of blocks you can search. For example Wallaby supports a maximum range of 2880 See https://github.com/Zondax/rosetta-filecoin/blob/b395b3e04401be26c6cdf6a419e14ce85e2f7331/tools/wallaby/files/config.toml#L243
const REQUIRED_BLOCK_CONFIRMATIONS = 2
REQUIRED_BLOCK_CONFIRMATIONS is how many blocks must be mined before an emitted event is processed
const RESUB_INTERVAL = 15 * time.Second
RESUB_INTERVAL is how often we resubscribe to log events. We do this to avoid https://github.com/ethereum/go-ethereum/issues/23845 We use 2.5 minutes as the default filter timeout is 5 minutes. See https://github.com/ethereum/go-ethereum/blob/e14164d516600e9ac66f9060892e078f5c076229/eth/filters/filter_system.go#L43 This has been reduced to 15 seconds to support local devnets with much shorter timeouts.
const TEST_CHAIN_ID = 1337
This is the chain id used by the simulated backend as well as hardhat
Variables ¶
var ErrUnableToAssignBigInt = errors.New("simulated_backend_chainservice: unable to assign BigInt")
Functions ¶
func NewEventTracker ¶ added in v0.1.1
func NewEventTracker(startBlock uint64) *eventTracker
func SetupSimulatedBackend ¶
func SetupSimulatedBackend(numAccounts uint64) (SimulatedChain, Bindings, []*bind.TransactOpts, error)
SetupSimulatedBackend creates a new SimulatedBackend with the supplied number of transacting accounts, deploys the Nitro Adjudicator and returns both.
Types ¶
type AllocationUpdatedEvent ¶
type AllocationUpdatedEvent struct {
// contains filtered or unexported fields
}
AllocationUpdated is an internal representation of the AllocationUpdated blockchain event The event includes the token address and amount at the block that generated the event
func NewAllocationUpdatedEvent ¶
func NewAllocationUpdatedEvent(channelId types.Destination, blockNum uint64, txIndex uint, assetAddress common.Address, assetAmount *big.Int) AllocationUpdatedEvent
func (AllocationUpdatedEvent) ChannelID ¶
func (ce AllocationUpdatedEvent) ChannelID() types.Destination
func (AllocationUpdatedEvent) String ¶
func (aue AllocationUpdatedEvent) String() string
type BackendWrapper ¶
type BackendWrapper struct {
*backends.SimulatedBackend
}
This is used to wrap the simulated backend so that we can provide a ChainID function like a real eth client
type Bindings ¶
type Bindings struct { Adjudicator binding[NitroAdjudicator.NitroAdjudicator] Token binding[Token.Token] ConsensusApp binding[ConsensusApp.ConsensusApp] VirtualPaymentApp binding[VirtualPaymentApp.VirtualPaymentApp] }
type ChainEventHandler ¶
ChainEventHandler describes an objective that can handle chain events
type ChainService ¶
type ChainService interface { // EventFeed returns a chan for receiving events from the chain service. EventFeed() <-chan Event // SendTransaction is for sending transactions with the chain service SendTransaction(protocols.ChainTransaction) error // GetConsensusAppAddress returns the address of a deployed ConsensusApp (for ledger channels) GetConsensusAppAddress() types.Address // GetVirtualPaymentAppAddress returns the address of a deployed VirtualPaymentApp GetVirtualPaymentAppAddress() types.Address // GetChainId returns the id of the chain the service is connected to GetChainId() (*big.Int, error) // GetLastConfirmedBlockNum returns the highest blockNum that satisfies the chainservice's REQUIRED_BLOCK_CONFIRMATIONS GetLastConfirmedBlockNum() uint64 // Close closes the ChainService Close() error }
func NewEthChainService ¶
func NewEthChainService(chainOpts ChainOpts) (ChainService, error)
NewEthChainService is a convenient wrapper around newEthChainService, which provides a simpler API
func NewSimulatedBackendChainService ¶
func NewSimulatedBackendChainService(sim SimulatedChain, bindings Bindings, txSigner *bind.TransactOpts, ) (ChainService, error)
NewSimulatedBackendChainService constructs a chain service that submits transactions to a NitroAdjudicator and listens to events from an eventSource
type ChallengeRegisteredEvent ¶
type ChallengeRegisteredEvent struct {
// contains filtered or unexported fields
}
func NewChallengeRegisteredEvent ¶
func NewChallengeRegisteredEvent( channelId types.Destination, blockNum uint64, txIndex uint, variablePart state.VariablePart, sigs []state.Signature, ) ChallengeRegisteredEvent
NewChallengeRegisteredEvent constructs a ChallengeRegisteredEvent
func (ChallengeRegisteredEvent) ChannelID ¶
func (ce ChallengeRegisteredEvent) ChannelID() types.Destination
func (ChallengeRegisteredEvent) Outcome ¶
func (cr ChallengeRegisteredEvent) Outcome() outcome.Exit
Outcome returns the outcome which will have been stored on chain in the adjudicator after the ChallengeRegistered Event fires.
func (ChallengeRegisteredEvent) SignedState ¶
func (cr ChallengeRegisteredEvent) SignedState(fp state.FixedPart) (state.SignedState, error)
SignedState returns the signed state which will have been stored on chain in the adjudicator after the ChallengeRegistered Event fires.
func (ChallengeRegisteredEvent) StateHash ¶
StateHash returns the statehash stored on chain at the time of the ChallengeRegistered Event firing.
func (ChallengeRegisteredEvent) String ¶
func (cr ChallengeRegisteredEvent) String() string
type ConcludedEvent ¶
type ConcludedEvent struct {
// contains filtered or unexported fields
}
ConcludedEvent is an internal representation of the Concluded blockchain event
func (ConcludedEvent) ChannelID ¶
func (ce ConcludedEvent) ChannelID() types.Destination
func (ConcludedEvent) String ¶
func (ce ConcludedEvent) String() string
type DepositedEvent ¶
type DepositedEvent struct { Asset types.Address NowHeld *big.Int // contains filtered or unexported fields }
DepositedEvent is an internal representation of the deposited blockchain event
func NewDepositedEvent ¶
func NewDepositedEvent(channelId types.Destination, blockNum uint64, txIndex uint, assetAddress common.Address, nowHeld *big.Int) DepositedEvent
func (DepositedEvent) ChannelID ¶
func (ce DepositedEvent) ChannelID() types.Destination
func (DepositedEvent) String ¶
func (de DepositedEvent) String() string
type EthChainService ¶
type EthChainService struct {
// contains filtered or unexported fields
}
eventTracker holds on to events in memory and dispatches an event after required number of confirmations
func (*EthChainService) Close ¶
func (ecs *EthChainService) Close() error
func (*EthChainService) EventFeed ¶
func (ecs *EthChainService) EventFeed() <-chan Event
EventFeed returns the out chan, and narrows the type so that external consumers may only receive on it.
func (*EthChainService) GetChainId ¶
func (ecs *EthChainService) GetChainId() (*big.Int, error)
func (*EthChainService) GetConsensusAppAddress ¶
func (ecs *EthChainService) GetConsensusAppAddress() types.Address
func (*EthChainService) GetLastConfirmedBlockNum ¶ added in v0.1.1
func (ecs *EthChainService) GetLastConfirmedBlockNum() uint64
func (*EthChainService) GetVirtualPaymentAppAddress ¶
func (ecs *EthChainService) GetVirtualPaymentAppAddress() types.Address
func (*EthChainService) SendTransaction ¶
func (ecs *EthChainService) SendTransaction(tx protocols.ChainTransaction) error
SendTransaction sends the transaction and blocks until it has been submitted.
type Event ¶
type Event interface { ChannelID() types.Destination BlockNum() uint64 TxIndex() uint }
Event dictates which methods all chain events must implement
type MockChain ¶
type MockChain struct { BlockNum uint64 // contains filtered or unexported fields }
MockChain mimics the Ethereum blockchain by keeping track of block numbers and account balances in memory. MockChain accepts transactions and broadcasts events.
func (*MockChain) SubmitTransaction ¶
func (mc *MockChain) SubmitTransaction(tx protocols.ChainTransaction) error
SubmitTransaction updates internal state and broadcasts events unlike an ethereum blockchain, MockChain accepts go-nitro protocols.ChainTransaction
type MockChainService ¶
type MockChainService struct {
// contains filtered or unexported fields
}
MockChainService adheres to the ChainService interface. The constructor accepts a MockChain, which allows multiple clients to share the same, in-memory chain.
func NewMockChainService ¶
func NewMockChainService(chain *MockChain, address common.Address) *MockChainService
NewMockChainService returns a new MockChainService.
func (*MockChainService) Close ¶
func (mc *MockChainService) Close() error
func (*MockChainService) EventFeed ¶
func (mc *MockChainService) EventFeed() <-chan Event
func (*MockChainService) GetChainId ¶
func (mc *MockChainService) GetChainId() (*big.Int, error)
func (*MockChainService) GetConsensusAppAddress ¶
func (mc *MockChainService) GetConsensusAppAddress() types.Address
GetConsensusAppAddress returns the zero address, since the mock chain will not run any application logic.
func (*MockChainService) GetLastConfirmedBlockNum ¶ added in v0.1.1
func (mc *MockChainService) GetLastConfirmedBlockNum() uint64
func (*MockChainService) GetVirtualPaymentAppAddress ¶
func (mc *MockChainService) GetVirtualPaymentAppAddress() types.Address
GetVirtualPaymentAppAddress returns the zero address, since the mock chain will not run any application logic.
func (*MockChainService) SendTransaction ¶
func (mc *MockChainService) SendTransaction(tx protocols.ChainTransaction) error
SendTransaction responds to the given tx.
type SimulatedBackendChainService ¶
type SimulatedBackendChainService struct { *EthChainService // contains filtered or unexported fields }
SimulatedBackendChainService extends EthChainService to automatically mine a block for every transaction
func (*SimulatedBackendChainService) GetConsensusAppAddress ¶
func (sbcs *SimulatedBackendChainService) GetConsensusAppAddress() types.Address
func (*SimulatedBackendChainService) GetVirtualPaymentAppAddress ¶
func (sbcs *SimulatedBackendChainService) GetVirtualPaymentAppAddress() types.Address
GetVirtualPaymentAppAddress returns the address of a deployed VirtualPaymentApp
func (*SimulatedBackendChainService) SendTransaction ¶
func (sbcs *SimulatedBackendChainService) SendTransaction(tx protocols.ChainTransaction) error
SendTransaction sends the transaction and blocks until it has been mined.
type SimulatedChain ¶
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
package NitroAdjudicator contains bindings generated from the Nitro Adjudicator solidity contract, as well as utilities for converting client types to on-chain types.
|
package NitroAdjudicator contains bindings generated from the Nitro Adjudicator solidity contract, as well as utilities for converting client types to on-chain types. |