Package convex.core

Class BeliefMerge

java.lang.Object
convex.core.BeliefMerge

public class BeliefMerge extends Object
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 Details

    • create

      public static BeliefMerge create(Belief belief, AKeyPair kp, long timestamp, State s)
      Create a Belief Merge context
      Parameters:
      belief - Initial Belief
      kp - Keypair for Belief Merge
      timestamp - Timestamp
      s - Consensus State
      Returns:
      New MergeContext instance
    • merge

      public Belief merge(Belief... beliefs) throws InvalidDataException
      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

      public Belief mergeOrders(Belief b)
      Merge orders from a second Belief
      Parameters:
      b - Belief from which to merge order
      Returns:
      Belief with updated orders (or the same Belief if unchanged)
    • 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 Orders
      peerStakes - A map of peers addresses to weighted stakes for each peer
      dest - Destination hashmap to store the stakes for each Order
      Returns:
      The total stake of all chains among peers under consideration
    • computeWinningOrder

      public static 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 Order
      consensusPoint - Current consensus point
      initialTotalStake - Total stake under consideration
      Returns:
      Vector of Blocks in winning Order
    • computeVote

      public static <V> double computeVote(HashMap<V,Double> m)
      Computes the total vote for all entries in a HashMap
      Type Parameters:
      V - The type of values used as keys in the HashMap
      Parameters:
      m - A map of values to votes
      Returns:
      The total voting stake
    • compareOrders

      public static boolean compareOrders(Order oldOrder, Order newOrder)
      Checks if a new Order should replace the current order when collecting Peer orders
      Parameters:
      oldOrder - Current Order
      newOrder - Potential new ORder
      Returns:
    • getAccountKey

      public AccountKey getAccountKey()
      Get the address of the current Peer (the one performing the merge)
      Returns:
      The Address of the peer.
    • sign

      public <T extends ACell> SignedData<T> sign(T value)
      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

      public BeliefMerge withTimestamp(long newTimestamp)
      Updates the timestamp of this MergeContext
      Parameters:
      newTimestamp - New timestamp
      Returns:
      Updated MergeContext
    • getConsensusState

      public State getConsensusState()
      Gets the Consensus State for this merge
      Returns:
      Consensus State