- All Implemented Interfaces:
IAssociative<Keyword,,ACell> IValidated,IWriteable,Map<Keyword,ACell>
Class representing a Peer's view of the overall network consensus state.
Belief is immutable, and is designed to be independent of any particular Peer
so that it can be efficiently merged towards consensus.
Belief can be merged with other Beliefs from the perspective of a Peer. This
property is fundamental to the Convex consensus algorithm.
"Sorry to be a wet blanket. Writing a description for this thing for general
audiences is bloody hard. There's nothing to relate it to." – Satoshi
Nakamoto
-
Nested Class Summary
-
Field Summary
Fields inherited from class convex.core.data.ARecord
DEFAULT_VALUEFields inherited from class convex.core.data.ADataStructure
countFields inherited from class convex.core.data.ACell
cachedRef, memorySize -
Method Summary
Modifier and TypeMethodDescriptionstatic BeliefCreate a Belief with a single order signed by the given key pair, using initial timestamp.static Beliefcreate(SignedData<Order>... orders) static Beliefcreate(HashMap<AccountKey, SignedData<Order>> orderMap) static BeliefCreate a Belief with a single empty order.intencode(byte[] bs, int pos) Writes this Cell's encoding to a byte array, including a tag byte which will be written first.intencodeRaw(byte[] bs, int pos) Encodes this BeliefbooleanTests if this Belief is equal to anotherbooleanChecks for equality with another Cell.intEstimate the encoded data size for this Cell.static Collection<SignedData<Order>> extractOrders(ACell payload) Extract a collection of Orders from a Cell, suitable for Belief mergeGets the record field content for a given key, or null if not found.Gets the RecordFormat instance that describes this Record's layoutgetOrder(AccountKey address) Gets the current Order for a given Address within this Belief.Get the map of orders for this BeliefGets a new HashMap containing all OrdersgetRef(int i) Gets a numbered child Ref from within this Cell.intGets the number of Refs contained within this Cell.bytegetTag()Gets the tag byte for this record type.static Beliefinitial()Gets an empty BeliefproposeBlock(AKeyPair kp, SignedData<Block> signedBlock) Propose a new Block at the end of the current Orderstatic BeliefupdateRefs(IRefFunction func) Updates all child Refs in this object using the given function.voidValidates the local structure and invariants of this cell.withOrders(Index<AccountKey, SignedData<Order>> newOrders) Updates this Belief with a new set of Chains for each peer addressMethods inherited from class convex.core.data.ARecord
accumulateEntrySet, accumulateKeySet, accumulateValues, assoc, assocEntry, containsKey, containsValue, dissoc, dissoc, empty, entryAt, entrySet, forEach, get, getEntry, getEntryByHash, getKeyRefEntry, getKeys, getType, getValuesArray, isCanonical, isCVMValue, keySet, reduceEntries, reduceValues, toCanonical, toHashMap, valuesMethods inherited from class convex.core.data.AMap
clear, conj, containsKey, containsKeyRef, containsValue, entryVector, filterValues, get, get, get, getElementRef, merge, print, put, putAll, remove, slice, sliceMethods inherited from class convex.core.data.ADataStructure
checkIndex, conjAll, count, isDataValue, isEmpty, size, toCVMStringMethods inherited from class convex.core.data.ACell
attachMemorySize, attachRef, cachedEncoding, cachedHash, calcMemorySize, createEncoding, createRef, equals, genericEquals, getCanonical, getChildRefs, getEncoding, getEncodingLength, getHash, getMemorySize, getMemorySize, getRef, hashCode, isEmbedded, toString, validateMethods inherited from class convex.core.data.AObject
attachEncoding, print, printMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, getOrDefault, hashCode, isEmpty, merge, putIfAbsent, remove, replace, replace, replaceAll, size
-
Method Details
-
get
Description copied from class:ARecordGets the record field content for a given key, or null if not found. -
updateRefs
Description copied from class:ACellUpdates all child Refs in this object using the given function. This clears the currently cached Ref if an update occurred. This is because, presumably, a new Ref for this cell needs to be created. The function *must not* change the hash value of Refs, in order to ensure structural integrity of modified data structures. The implementation *should* re-attach any original encoding in order to prevent re-encoding or surplus hashing This is a building block for a very sneaky trick that enables use to do a lot of efficient operations on large trees of smart references. Must return the same object if no Refs are altered.- Overrides:
updateRefsin classACell- Parameters:
func- Ref update function- Returns:
- Cell with updated Refs
-
initial
Gets an empty Belief- Returns:
- Empty Belief
-
create
Create a Belief with a single order signed by the given key pair, using initial timestamp.- Parameters:
kp- Peer Key pair with which to sign the order.order- Order of blocks that the Peer is proposing- Returns:
- new Belief representing the isolated belief of a single Peer.
-
create
-
create
-
createSingleOrder
Create a Belief with a single empty order. USeful for Peer startup.- Parameters:
kp- Keypair for Peer- Returns:
- New Belief
-
withOrders
Updates this Belief with a new set of Chains for each peer address- Parameters:
newOrders- New map of peer keys to Orders- Returns:
- The updated belief, or the same Belief if no change.
-
encode
public int encode(byte[] bs, int pos) Description copied from class:ACellWrites this Cell's encoding to a byte array, including a tag byte which will be written first. Cell must be canonical, or else an error may occur.- Specified by:
encodein interfaceIWriteable- Specified by:
encodein classACell- Parameters:
bs- A byte array to which to write the encodingpos- The offset into the byte array- Returns:
- New position after writing
-
estimatedEncodingSize
public int estimatedEncodingSize()Description copied from interface:IWriteableEstimate the encoded data size for this Cell. Used for quickly sizing buffers. Implementations should try to return a size that is highly likely to contain the entire object when encoded, including the tag byte. Should not traverse soft Refs, i.e. must be usable on arbitrary partial data structures- Specified by:
estimatedEncodingSizein interfaceIWriteable- Overrides:
estimatedEncodingSizein classARecord- Returns:
- The estimated size for the binary representation of this object.
-
read
- Throws:
BadFormatException
-
encodeRaw
public int encodeRaw(byte[] bs, int pos) Encodes this Belief -
getTag
public byte getTag()Description copied from class:ARecordGets the tag byte for this record type. The Tag is the byte used to identify the record in the binary encoding. -
getOrder
Gets the current Order for a given Address within this Belief.- Parameters:
address- Address of peer- Returns:
- The chain for the peer within this Belief, or null if noy found.
-
getOrders
Get the map of orders for this Belief- Returns:
- Orders map
-
validateCell
Description copied from class:ACellValidates the local structure and invariants of this cell. Called by validate() super implementation. Should validate directly contained data, but should not validate all other structure of this cell. In particular, should not traverse potentially missing child Refs.- Specified by:
validateCellin classACell- Throws:
InvalidDataException- If the Cell is invalid
-
equals
Description copied from class:ACellChecks for equality with another Cell. In general, Cells are considered equal if they have the same canonical representation, i.e. an identical encoding with the same hash value. Subclasses SHOULD override this if they have a more efficient equals implementation. MUST NOT require reads from Store. -
equals
Tests if this Belief is equal to another- Parameters:
a- Belief to compare with- Returns:
- true if equal, false otherwise
-
getRefCount
public int getRefCount()Description copied from class:ACellGets the number of Refs contained within this Cell. This number is final / immutable for any given instance and is defined by the Cell encoding rules. Contained Refs may be either external or embedded.- Overrides:
getRefCountin classACell- Returns:
- The number of Refs in this Cell
-
getRef
Description copied from class:ACellGets a numbered child Ref from within this Cell. WARNING: May need to convert to a canonical instance -
getOrdersHashMap
Gets a new HashMap containing all Orders- Returns:
- HashMap of current orders
-
getFormat
Description copied from class:ARecordGets the RecordFormat instance that describes this Record's layout -
extractOrders
Extract a collection of Orders from a Cell, suitable for Belief merge- Parameters:
payload- Cell to extra orders from- Returns:
- Collection of signed orders
-
proposeBlock
Propose a new Block at the end of the current Order- Parameters:
kp- Keypair with which to sign OrdersignedBlock- Signed Block of transactions- Returns:
- Updated Belief with new Order
-