Package convex.core
Class Peer
java.lang.Object
convex.core.Peer
Immutable class representing the encapsulated state of a Peer
SECURITY:- Needs to contain the Peer's unlocked private key for online signing.
- Manages Peer state transitions given external events. Must do so correctly.
Must have at least one state, the initial state. New states will be added as consensus updates happen.
"Don't worry about what anybody else is going to do. The best way to predict the future is to invent it." - Alan Kay-
Method Summary
Modifier and TypeMethodDescriptionstatic Peer
Creates a Peerstatic Peer
Create a Peer instance from a remotely acquired Beliefstatic Peer
createGenesisPeer
(AKeyPair keyPair, State genesisState) Creates a new Peer instance at server startup using the provided configuration.executeDetached
(ATransaction transaction) Executes a "detached" transaction on the current consensus state of this Peer, but without any effect on current CVM state.executeQuery
(ACell form) Executes a query in this Peer's current Consensus State, using a default addressexecuteQuery
(ACell form, Address address) Compiles and executes a query on the current consensus state of this Peer.static Peer
Constructs a Peer instance from persisted PEer DataGet the current Belief of this PeergetBlockResult
(long i) Gets the BlockResult of a specific block indexGets the current consensus state for this PeerGets the controller Address for this Peerlong
Gets the Final Point for this PeerGets the genesis State of this PeerGets the Peer Key of this Peer.Get the Network ID for this PEergetOrder
(AccountKey peerKey) Gets the current chain this Peer sees for a given peer addressgetPeerData
(AStore store) LikegetPeerData(AStore, ACell)
but uses a null root key.getPeerData
(AStore store, ACell rootKey) Gets Peer Data from a Store.Gets the Peer Public Key of this Peer.Gets the current Order for this PeergetResult
(long blockIndex, long txIndex) Gets the Result of a specific transactionlong
Gets the state position of this Peer, which is equal to the number of state transitions executed.long
Gets the timestamp of this PeermergeBeliefs
(Belief... beliefs) Merges a set of new Beliefs into this Peer's belief.proposeBlock
(Block block) Propose a new Block.pruneHistory
(long ts) Prunes History before the given timestampstatic Peer
restorePeer
(AStore store, AKeyPair keyPair) LikerestorePeer(AStore, AKeyPair, ACell)
but uses a null root key.static Peer
restorePeer
(AStore store, AKeyPair keyPair, ACell rootKey) Restores a Peer from the Etch database specified in Config<T extends ACell>
SignedData<T> sign
(T value) Signs a value with the keypair of this PeertoData()
Gets the Peer Data map for this PeerupdateBelief
(Belief newBelief) Update this Peer with a new consensus BeliefUpdates the state of the Peer based on latest consensus BeliefupdateTimestamp
(long newTimestamp) Updates the timestamp to the specified time, going forwards only
-
Method Details
-
fromData
-
toData
-
create
-
create
-
restorePeer
LikerestorePeer(AStore, AKeyPair, ACell)
but uses a null root key.- Parameters:
store
- Store to restore fromkeyPair
- Key Pair to use for restored Peer- Returns:
- Restored Peer instance
- Throws:
IOException
- In case of IO error
-
restorePeer
Restores a Peer from the Etch database specified in Config- Parameters:
store
- Store to restore fromkeyPair
- Key Pair to use for restored PeerrootKey
- When not null, assumes the root data is a map and peer data is under that key- Returns:
- Peer instance, or null if root hash was not found
- Throws:
IOException
- If store reading failed
-
getPeerData
LikegetPeerData(AStore, ACell)
but uses a null root key.- Parameters:
store
- store from which to load Peer data- Returns:
- Peer data map
- Throws:
IOException
- In case of IOException
-
getPeerData
Gets Peer Data from a Store.- Parameters:
store
- Store to retrieve Peer Data fromrootKey
- When not null, assumes the root data is a map and peer data is under that key- Returns:
- Peer data map, or null if not available
- Throws:
IOException
- If a store IO error occurs
-
createGenesisPeer
Creates a new Peer instance at server startup using the provided configuration. Current store must be set to store for server.- Parameters:
keyPair
- Key pair for genesis peergenesisState
- Genesis state, or null to generate fresh state- Returns:
- A new Peer instance
-
updateTimestamp
Updates the timestamp to the specified time, going forwards only- Parameters:
newTimestamp
- New Peer timestamp- Returns:
- This peer updated with the given timestamp
-
executeQuery
Compiles and executes a query on the current consensus state of this Peer.- Parameters:
form
- Form to compile and execute.address
- Address to use for query execution. If null, core address will be used- Returns:
- The Context containing the query results. Will be NOBODY error if address / account does not exist
-
executeDetached
Executes a "detached" transaction on the current consensus state of this Peer, but without any effect on current CVM state. This can be used for query, estimating potential fees etc.- Parameters:
transaction
- Transaction to execute- Returns:
- The Context containing the transaction results.
-
executeQuery
Executes a query in this Peer's current Consensus State, using a default address- Parameters:
form
- Form to execute as a Query- Returns:
- Context after executing query
-
getTimestamp
public long getTimestamp()Gets the timestamp of this Peer- Returns:
- Timestamp
-
getPeerKey
-
getController
Gets the controller Address for this Peer- Returns:
- Address of Peer controller Account, or null if does not exist
-
getKeyPair
-
getBelief
-
sign
Signs a value with the keypair of this Peer- Type Parameters:
T
- Type of value to sign- Parameters:
value
- Value to sign- Returns:
- Signed data value
-
getConsensusState
Gets the current consensus state for this Peer- Returns:
- Consensus state for this chain (genesis state if no block consensus)
-
mergeBeliefs
Merges a set of new Beliefs into this Peer's belief. Beliefs may be null, in which case they are ignored. Should call updateState() at some point after this to update the global consensus state- Parameters:
beliefs
- An array of Beliefs. May contain nulls, which will be ignored.- Returns:
- Updated Peer after Belief Merge
- Throws:
InvalidDataException
- if
-
pruneHistory
Prunes History before the given timestamp- Parameters:
ts
- Timestamp from which to to keep History- Returns:
- Updated Peer with pruned History
-
updateBelief
-
updateState
Updates the state of the Peer based on latest consensus Belief- Returns:
- Updated Peer
-
getResult
Gets the Result of a specific transaction- Parameters:
blockIndex
- Index of Block in OrdertxIndex
- Index of transaction in block- Returns:
- Result from transaction, or null if the transaction does not exist or is no longer stored
-
getBlockResult
Gets the BlockResult of a specific block index- Parameters:
i
- Index of Block- Returns:
- BlockResult, or null if the BlockResult is not stired
-
proposeBlock
-
getFinalityPoint
public long getFinalityPoint()Gets the Final Point for this Peer- Returns:
- Consensus Point value
-
getPeerOrder
Gets the current Order for this Peer- Returns:
- The Order for this peer in its current Belief. Will return null if the Peer is not a peer in the current consensus state
-
getOrder
Gets the current chain this Peer sees for a given peer address- Parameters:
peerKey
- Peer Key- Returns:
- The current Order for the specified peer
-
getNetworkID
-
getStatePosition
public long getStatePosition()Gets the state position of this Peer, which is equal to the number of state transitions executed.- Returns:
- Position
-
getGenesisState
-