Package org.bitcoinj.utils
Class VersionTally
- java.lang.Object
-
- org.bitcoinj.utils.VersionTally
-
public class VersionTally extends java.lang.Object
Caching counter for the block versions within a moving window. This class is NOT thread safe (as if two threads are trying to use it concurrently, there's risk of getting versions out of sequence).
-
-
Constructor Summary
Constructors Constructor Description VersionTally(NetworkParameters params)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(long version)
Add a new block version to the tally, and return the count for that version within the window.java.lang.Integer
getCountAtOrAbove(long version)
Get the count of blocks at or above the given version, within the window.void
initialize(BlockStore blockStore, StoredBlock chainHead)
Initialize the version tally from the block store.int
size()
Get the size of the version window.
-
-
-
Constructor Detail
-
VersionTally
public VersionTally(NetworkParameters params)
-
-
Method Detail
-
add
public void add(long version)
Add a new block version to the tally, and return the count for that version within the window.- Parameters:
version
- the block version to add.
-
getCountAtOrAbove
public java.lang.Integer getCountAtOrAbove(long version)
Get the count of blocks at or above the given version, within the window.- Parameters:
version
- the block version to query.- Returns:
- the count for the block version, or null if the window is not yet full.
-
initialize
public void initialize(BlockStore blockStore, StoredBlock chainHead) throws BlockStoreException
Initialize the version tally from the block store. Note this does not search backwards past the start of the block store, so if starting from a checkpoint this may not fill the window.- Parameters:
blockStore
- block store to load blocks from.chainHead
- current chain tip.- Throws:
BlockStoreException
-
size
public int size()
Get the size of the version window.
-
-