use of snowblossom.lib.ChainHash in project snowblossom by snowblossomcoin.
the class MonitorInterfaceSystemOut method onOutbound.
public void onOutbound(Transaction tx, int tx_out_idx) {
ChainHash hash = new ChainHash(tx.getTxHash());
System.out.println("Outbound tx: " + hash + " output: " + tx_out_idx);
}
use of snowblossom.lib.ChainHash in project snowblossom by snowblossomcoin.
the class Dancer method isCompliant.
/**
* Returns true iff the header is compliant with the dance.
* namely, if it is a coordinator, it includes only compliant other blocks.
* if it is not a coordinator, it includes only blocks the coordinator has included.
*/
public boolean isCompliant(BlockHeader header, int depth) {
if (depth == 0)
return true;
// this isn't a super strict check
if (header == null)
return true;
ChainHash hash = new ChainHash(header.getSnowHash());
synchronized (comp_cache) {
if (comp_cache.containsKey(hash)) {
return comp_cache.get(hash);
}
}
String key = hash.toString() + "/" + depth;
synchronized (comp_cache_depth) {
if (comp_cache_depth.containsKey(key)) {
return comp_cache_depth.get(key);
}
}
boolean comp = isCompliantInternal(header, depth);
synchronized (comp_cache_depth) {
comp_cache_depth.put(key, comp);
}
return comp;
}
use of snowblossom.lib.ChainHash in project snowblossom by snowblossomcoin.
the class Dancer method isCompliantInternal.
public boolean isCompliantInternal(BlockHeader header, int depth) {
int import_depth = node.getParams().getMaxShardSkewHeight() * 2 + 1;
int shard_id = header.getShardId();
if (isCoordinator(shard_id)) {
// For each imported block, make sure it is compliant
for (Map.Entry<Integer, BlockImportList> me : header.getShardImportMap().entrySet()) {
int imp_shard_id = me.getKey();
BlockImportList bil = me.getValue();
for (Map.Entry<Integer, ByteString> me_bil : bil.getHeightMap().entrySet()) {
int imp_height = me_bil.getKey();
ChainHash imp_hash = new ChainHash(me_bil.getValue());
BlockHeader imp_head = node.getForgeInfo().getHeader(imp_hash);
if (!isCompliant(imp_head, depth - 1))
return false;
}
}
} else {
Map<Integer, BlockHeader> my_heads = node.getForgeInfo().getImportedShardHeads(header, import_depth);
BlockHeader coord = node.getForgeInfo().getHighestCoordinator(my_heads.values());
if (!isCompliant(coord, depth - 1))
return false;
if (coord == null) {
logger.warning("Unable to find a coordinator for block: " + node.getForgeInfo().getHeaderString(header));
return true;
}
Map<Integer, BlockHeader> coord_heads = node.getForgeInfo().getImportedShardHeads(coord, import_depth);
// For each imported block in this current block, make sure that is in the coord_heads
for (Map.Entry<Integer, BlockImportList> me : header.getShardImportMap().entrySet()) {
int imp_shard_id = me.getKey();
BlockImportList bil = me.getValue();
for (Map.Entry<Integer, ByteString> me_bil : bil.getHeightMap().entrySet()) {
int imp_height = me_bil.getKey();
ChainHash imp_hash = new ChainHash(me_bil.getValue());
BlockHeader imp_head = node.getForgeInfo().getHeader(imp_hash);
if (!isCompliant(imp_head, depth - 1))
return false;
BlockHeader coord_head = coord_heads.get(imp_shard_id);
// Coordinator doesn't have shard
if (coord_head == null)
return false;
// or a parent of the shard in the coord_head
if (!node.getForgeInfo().isInChain(coord_head, imp_head)) {
return false;
}
}
}
}
// WOOO
return true;
}
use of snowblossom.lib.ChainHash in project snowblossom by snowblossomcoin.
the class Dancer method isCompliant.
public boolean isCompliant(BlockHeader header) {
if (comp_cache.size() > 20000) {
logger.info("comp cache full: " + comp_cache.size());
}
// this isn't a super strict check
if (header == null)
return true;
ChainHash hash = new ChainHash(header.getSnowHash());
synchronized (comp_cache) {
if (comp_cache.containsKey(hash)) {
return comp_cache.get(hash);
}
}
boolean comp = isCompliant(header, 3);
synchronized (comp_cache) {
comp_cache.put(hash, comp);
}
if (!comp) {
logger.warning("Block out of compliance: " + node.getForgeInfo().getHeaderString(header));
}
return comp;
}
use of snowblossom.lib.ChainHash in project snowblossom by snowblossomcoin.
the class DigestUtilTest method testMerkleRoot3.
@Test
public void testMerkleRoot3() {
ChainHash a = getRandomHash();
ChainHash b = getRandomHash();
ChainHash c = getRandomHash();
ChainHash result = DigestUtil.getMerkleRootForTxList(ImmutableList.of(a, b, c));
ChainHash ab = treeHash(a, b);
ChainHash ab_c = treeHash(ab, c);
Assert.assertEquals(ab_c, result);
}
Aggregations