Skip to content

Commit

Permalink
work on block explorer
Browse files Browse the repository at this point in the history
  • Loading branch information
fireduck64 committed May 21, 2018
1 parent 94ef23d commit 46039af
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 11 deletions.
2 changes: 1 addition & 1 deletion BUILD
Expand Up @@ -222,7 +222,7 @@ java_test(
name = "signature_test",
srcs = ["test/SignatureTest.java"],
test_class = "snowblossom.SignatureTest",
size="small",
size="medium",
deps = [
"@junit_junit//jar",
":snowblossomlib",
Expand Down
5 changes: 4 additions & 1 deletion proto/snowblossom.proto
Expand Up @@ -147,7 +147,6 @@ service UserService {
rpc GetUTXONode( GetUTXONodeRequest ) returns ( GetUTXONodeReply ) {}

rpc GetNodeStatus ( NullRequest ) returns ( NodeStatus ) {}
rpc GetHead ( NullRequest ) returns ( BlockHeader ) {}
rpc GetBlock ( RequestBlock ) returns ( Block ) {}
rpc GetTransaction ( RequestTransaction ) returns ( Transaction ) {}
rpc GetBlockHeader ( RequestBlockHeader ) returns ( BlockHeader ) {}
Expand Down Expand Up @@ -236,6 +235,8 @@ message NullRequest {
message NodeStatus {
int32 mem_pool_size = 1;
int32 connected_peers = 2;

BlockSummary head_summary = 3;
}

// -------------------------------------------------------------------
Expand All @@ -249,6 +250,8 @@ message BlockSummary {
int32 activated_field = 4;

BlockHeader header = 5;
int64 total_transactions = 6;

}

message MemPoolList {
Expand Down
5 changes: 3 additions & 2 deletions src/BlockIngestor.java
Expand Up @@ -82,7 +82,7 @@ public boolean ingestBlock(Block blk)
return false;
}

BlockSummary summary = getNewSummary(blk.getHeader(), prev_summary, node.getParams());
BlockSummary summary = getNewSummary(blk.getHeader(), prev_summary, node.getParams(), blk.getTransactionsCount() );

Validation.deepBlockValidation(node, blk, prev_summary);

Expand Down Expand Up @@ -147,7 +147,7 @@ public BlockSummary getHead()
return chainhead;
}

public static BlockSummary getNewSummary(BlockHeader header, BlockSummary prev_summary, NetworkParams params)
public static BlockSummary getNewSummary(BlockHeader header, BlockSummary prev_summary, NetworkParams params, long tx_count)
{
BlockSummary.Builder bs = BlockSummary.newBuilder();

Expand All @@ -160,6 +160,7 @@ public static BlockSummary getNewSummary(BlockHeader header, BlockSummary prev_s
BigInteger work_in_block = params.getMaxTarget().multiply(slice).divide(target);
BigInteger prev_work_sum = BlockchainUtil.readInteger(prev_summary.getWorkSum());

bs.setTotalTransactions( prev_summary.getTotalTransactions() + tx_count );

BigInteger worksum = prev_work_sum.add(work_in_block);

Expand Down
2 changes: 2 additions & 0 deletions src/PeerLink.java
Expand Up @@ -96,9 +96,11 @@ public void onError(Throwable t)
@Override
public void onNext(PeerMessage msg)
{

last_received_message_time = System.currentTimeMillis();
try
{
msg = PeerMessage.parseFrom(msg.toByteString());
if (msg.hasTx())
{
Transaction tx = msg.getTx();
Expand Down
18 changes: 16 additions & 2 deletions src/SnowUserService.java
Expand Up @@ -136,8 +136,11 @@ public void submitTransaction(Transaction tx, StreamObserver<SubmitReply> respon
{
try
{
node.getMemPool().addTransaction(tx);
node.getPeerage().broadcastTransaction(tx);
tx = Transaction.parseFrom(tx.toByteString());
if (node.getMemPool().addTransaction(tx))
{
node.getPeerage().broadcastTransaction(tx);
}
}
catch(ValidationException e)
{
Expand All @@ -150,6 +153,16 @@ public void submitTransaction(Transaction tx, StreamObserver<SubmitReply> respon
responseObserver.onCompleted();
return;
}
catch(com.google.protobuf.InvalidProtocolBufferException e)
{
logger.info("Rejecting transaction, strange error: " + e);
responseObserver.onNext(SubmitReply.newBuilder()
.setSuccess(false)
.setErrorMessage(e.toString())
.build());
responseObserver.onCompleted();
return;
}

responseObserver.onNext(SubmitReply.newBuilder().setSuccess(true).build());
responseObserver.onCompleted();
Expand Down Expand Up @@ -203,6 +216,7 @@ public void getNodeStatus(NullRequest null_request, StreamObserver<NodeStatus> r
NodeStatus ns = NodeStatus.newBuilder()
.setMemPoolSize(node.getMemPool().getMemPoolSize())
.setConnectedPeers(node.getPeerage().getConnectedPeerCount())
.setHeadSummary(node.getBlockIngestor().getHead())
.build();

responseObserver.onNext(ns);
Expand Down
2 changes: 1 addition & 1 deletion src/client/SnowBlossomClient.java
Expand Up @@ -242,7 +242,7 @@ public WalletDatabase makeNewDatabase()
{
WalletDatabase.Builder builder = WalletDatabase.newBuilder();

for(int i=0;i<8; i++)
for(int i=0;i<800; i++)
{
genNewKey(builder);
}
Expand Down
Binary file removed src/shackleton/.WebServer.java.swp
Binary file not shown.
4 changes: 2 additions & 2 deletions test/BlockIngestorTest.java
Expand Up @@ -28,7 +28,7 @@ public void testFirstBlockSummary()
prev_summary = BlockSummary.newBuilder().build();
System.out.println(prev_summary);

BlockSummary s = BlockIngestor.getNewSummary(header, prev_summary, params);
BlockSummary s = BlockIngestor.getNewSummary(header, prev_summary, params, 1L);

Assert.assertNotNull(s.getHeader());
Assert.assertEquals("1024", s.getWorkSum());
Expand Down Expand Up @@ -65,7 +65,7 @@ public void testMagicBlockSummary()
.build();
System.out.println(prev_summary);

BlockSummary s = BlockIngestor.getNewSummary(header, prev_summary, params);
BlockSummary s = BlockIngestor.getNewSummary(header, prev_summary, params, 1L);

BigInteger expected_target = params.getMaxTarget().multiply(BigInteger.valueOf(990L)).add(using_target.multiply(BigInteger.valueOf(10L))).divide(BigInteger.valueOf(1000L));
long expected_time = (params.getBlockTimeTarget() * 990L + using_time * 10L) / 1000L;
Expand Down
4 changes: 2 additions & 2 deletions test/PowUtilTest.java
Expand Up @@ -129,7 +129,7 @@ public void testStability()
.setTimestamp(time)
.build();

bs = BlockIngestor.getNewSummary(header, bs, params);
bs = BlockIngestor.getNewSummary(header, bs, params, 1L);

Assert.assertEquals(time, bs.getHeader().getTimestamp());

Expand Down Expand Up @@ -161,7 +161,7 @@ public void testStability()
.setTimestamp(time)
.build();

bs = BlockIngestor.getNewSummary(header, bs, params);
bs = BlockIngestor.getNewSummary(header, bs, params, 1L);

Assert.assertEquals(time, bs.getHeader().getTimestamp());

Expand Down

0 comments on commit 46039af

Please sign in to comment.