Package convex.core
Class BeliefMerge
java.lang.Object
convex.core.BeliefMerge
Class representing the context to be used for a Belief merge/update function. This
context must be created by a Peer to perform a valid Belief merge. It can be safely
discarded after use.
SECURITY: contains a hot key pair! We need this to sign new belief updates
including any chains we want to communicate. Don't allow this to leak
anywhere!
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleancompareOrders(Order oldOrder, Order newOrder) Checks if a new Order should replace the current order when collecting Peer ordersstatic <V> doublecomputeVote(HashMap<V, Double> m) Computes the total vote for all entries in a HashMapcomputeWinningOrder(HashMap<Order, Double> stakedOrders, long consensusPoint, double initialTotalStake) Compute the new winning Order for this Peer, including any new blocks encounteredstatic BeliefMergeCreate a Belief Merge contextGet the address of the current Peer (the one performing the merge)Gets the Consensus State for this mergelongGets the timestamp of this mergeThe Belief merge functionMerge orders from a second Beliefstatic doubleprepareStakedOrders(AMap<AccountKey, SignedData<Order>> peerOrders, HashMap<AccountKey, Double> peerStakes, HashMap<Order, Double> dest) Compute the total stake for every distinct Order seen.<T extends ACell>
SignedData<T> sign(T value) Sign a value using the keypair for this MergeContextwithTimestamp(long newTimestamp) Updates the timestamp of this MergeContext
-
Method Details
-
create
Create a Belief Merge context- Parameters:
belief- Initial Beliefkp- Keypair for Belief Mergetimestamp- Timestamps- Consensus State- Returns:
- New MergeContext instance
-
merge
The Belief merge function- Parameters:
beliefs- An array of Beliefs. May contain nulls, which will be ignored.- Returns:
- The updated merged belief with latest timestamp, or the same Belief if there is no change to Orders.
- Throws:
InvalidDataException- In case of invalid data
-
mergeOrders
-
prepareStakedOrders
public static double prepareStakedOrders(AMap<AccountKey, SignedData<Order>> peerOrders, HashMap<AccountKey, Double> peerStakes, HashMap<Order, Double> dest) Compute the total stake for every distinct Order seen. Stores results in a map of Orders to staked value.- Parameters:
peerOrders- A map of peer addresses to signed proposed OrderspeerStakes- A map of peers addresses to weighted stakes for each peerdest- Destination hashmap to store the stakes for each Order- Returns:
- The total stake of all chains among peers under consideration
-
computeWinningOrder
public AVector<SignedData<Block>> computeWinningOrder(HashMap<Order, Double> stakedOrders, long consensusPoint, double initialTotalStake) Compute the new winning Order for this Peer, including any new blocks encountered- Parameters:
stakedOrders- Amount of stake on each distinct OrderconsensusPoint- Current consensus pointinitialTotalStake- Total stake under consideration- Returns:
- Vector of Blocks in winning Order
-
computeVote
-
compareOrders
-
getAccountKey
Get the address of the current Peer (the one performing the merge)- Returns:
- The Address of the peer.
-
sign
Sign a value using the keypair for this MergeContext- Type Parameters:
T- Type of value- Parameters:
value- Value to sign- Returns:
- Signed value
-
getTimestamp
public long getTimestamp()Gets the timestamp of this merge- Returns:
- Timestamp
-
withTimestamp
Updates the timestamp of this MergeContext- Parameters:
newTimestamp- New timestamp- Returns:
- Updated MergeContext
-
getConsensusState
-