@@ -16,22 +16,24 @@ const {
1616 GenesisRules,
1717 GenesisOwners,
1818 AccountProperties,
19- ProofProperties ,
19+ StateInfoProperties ,
2020 StateVersions,
2121} = require ( '../common/constants' ) ;
2222const PathUtil = require ( '../common/path-util' ) ;
2323
2424class Block {
25- constructor ( lastHash , lastVotes , evidence , transactions , number , epoch , timestamp ,
25+ constructor ( lastHash , lastVotes , evidence , transactions , receipts , number , epoch , timestamp ,
2626 stateProofHash , proposer , validators , gasAmountTotal , gasCostTotal ) {
2727 this . last_votes = lastVotes ;
2828 this . evidence = evidence ;
2929 this . transactions = Block . sanitizeTransactions ( transactions ) ;
30+ this . receipts = receipts ;
3031 // Block's header
3132 this . last_hash = lastHash ;
3233 this . last_votes_hash = CommonUtil . hashString ( stringify ( lastVotes ) ) ;
3334 this . evidence_hash = CommonUtil . hashString ( stringify ( this . evidence ) ) ;
3435 this . transactions_hash = CommonUtil . hashString ( stringify ( this . transactions ) ) ;
36+ this . receipts_hash = CommonUtil . hashString ( stringify ( this . receipts ) ) ;
3537 this . number = number ;
3638 this . epoch = epoch ;
3739 this . timestamp = timestamp ;
@@ -50,6 +52,7 @@ class Block {
5052 last_hash : this . last_hash ,
5153 last_votes_hash : this . last_votes_hash ,
5254 transactions_hash : this . transactions_hash ,
55+ receipts_hash : this . receipts_hash ,
5356 evidence_hash : this . evidence_hash ,
5457 number : this . number ,
5558 epoch : this . epoch ,
@@ -67,6 +70,7 @@ class Block {
6770 last_votes : this . last_votes ,
6871 evidence : this . evidence ,
6972 transactions : this . transactions ,
73+ receipts : this . receipts ,
7074 } ;
7175 }
7276
@@ -92,9 +96,9 @@ class Block {
9296 return sizeof ( { ...block . header , ...block . body } ) ;
9397 }
9498
95- static create ( lastHash , lastVotes , evidence , transactions , number , epoch ,
99+ static create ( lastHash , lastVotes , evidence , transactions , receipts , number , epoch ,
96100 stateProofHash , proposer , validators , gasAmountTotal , gasCostTotal , timestamp ) {
97- return new Block ( lastHash , lastVotes , evidence , transactions , number , epoch ,
101+ return new Block ( lastHash , lastVotes , evidence , transactions , receipts , number , epoch ,
98102 timestamp ? timestamp : Date . now ( ) , stateProofHash , proposer , validators , gasAmountTotal ,
99103 gasCostTotal ) ;
100104 }
@@ -103,18 +107,18 @@ class Block {
103107 if ( ! Block . hasRequiredFields ( blockInfo ) ) return null ;
104108 if ( blockInfo instanceof Block ) return blockInfo ;
105109 return new Block ( blockInfo . last_hash , blockInfo . last_votes , blockInfo . evidence ,
106- blockInfo . transactions , blockInfo . number , blockInfo . epoch , blockInfo . timestamp ,
107- blockInfo . state_proof_hash , blockInfo . proposer , blockInfo . validators ,
110+ blockInfo . transactions , blockInfo . receipts , blockInfo . number , blockInfo . epoch ,
111+ blockInfo . timestamp , blockInfo . state_proof_hash , blockInfo . proposer , blockInfo . validators ,
108112 blockInfo . gas_amount_total , blockInfo . gas_cost_total ) ;
109113 }
110114
111115 static hasRequiredFields ( block ) {
112116 return ( block && block . last_hash !== undefined && block . last_votes !== undefined &&
113117 block . evidence !== undefined && block . transactions !== undefined &&
114- block . number !== undefined && block . epoch !== undefined && block . timestamp !== undefined &&
115- block . state_proof_hash !== undefined && block . proposer !== undefined &&
116- block . validators !== undefined && block . gas_amount_total !== undefined &&
117- block . gas_cost_total !== undefined ) ;
118+ block . receipts !== undefined && block . number !== undefined && block . epoch !== undefined &&
119+ block . timestamp !== undefined && block . state_proof_hash !== undefined &&
120+ block . proposer !== undefined && block . validators !== undefined &&
121+ block . gas_amount_total !== undefined && block . gas_cost_total !== undefined ) ;
118122 }
119123
120124 static validateHashes ( block ) {
@@ -129,6 +133,11 @@ class Block {
129133 `[${ LOG_HEADER } ] Transactions or transactions_hash is incorrect for block ${ block . hash } ` ) ;
130134 return false ;
131135 }
136+ if ( block . receipts_hash !== CommonUtil . hashString ( stringify ( block . receipts ) ) ) {
137+ logger . error (
138+ `[${ LOG_HEADER } ] Receipts or receipts_hash is incorrect for block ${ block . hash } ` ) ;
139+ return false ;
140+ }
132141 if ( block . last_votes_hash !== CommonUtil . hashString ( stringify ( block . last_votes ) ) ) {
133142 logger . error (
134143 `[${ LOG_HEADER } ] Last votes or last_votes_hash is incorrect for block ${ block . hash } ` ) ;
@@ -327,7 +336,7 @@ class Block {
327336
328337 static executeGenesisTxsAndGetData ( genesisTxs , genesisTime ) {
329338 const tempGenesisDb = new DB (
330- new StateNode ( StateVersions . EMPTY ) , StateVersions . EMPTY , null , null , false , - 1 , null ) ;
339+ new StateNode ( StateVersions . EMPTY ) , StateVersions . EMPTY , null , - 1 , null ) ;
331340 tempGenesisDb . initDbStates ( ) ;
332341 const resList = [ ] ;
333342 for ( const tx of genesisTxs ) {
@@ -341,9 +350,10 @@ class Block {
341350 }
342351 const { gasAmountTotal, gasCostTotal } = CommonUtil . getServiceGasCostTotalFromTxList ( genesisTxs , resList ) ;
343352 return {
344- stateProofHash : tempGenesisDb . getStateProof ( '/' ) [ ProofProperties . PROOF_HASH ] ,
353+ stateProofHash : tempGenesisDb . getProofHash ( '/' ) ,
345354 gasAmountTotal,
346- gasCostTotal
355+ gasCostTotal,
356+ receipts : CommonUtil . txResultsToReceipts ( resList ) ,
347357 } ;
348358 }
349359
@@ -361,9 +371,10 @@ class Block {
361371 const epoch = 0 ;
362372 const proposer = ownerAddress ;
363373 const validators = GENESIS_VALIDATORS ;
364- const { stateProofHash, gasAmountTotal, gasCostTotal } = Block . executeGenesisTxsAndGetData ( transactions , genesisTime ) ;
365- return new Block ( lastHash , lastVotes , evidence , transactions , number , epoch , genesisTime ,
366- stateProofHash , proposer , validators , gasAmountTotal , gasCostTotal ) ;
374+ const { stateProofHash, gasAmountTotal, gasCostTotal, receipts } =
375+ Block . executeGenesisTxsAndGetData ( transactions , genesisTime ) ;
376+ return new Block ( lastHash , lastVotes , evidence , transactions , receipts , number , epoch ,
377+ genesisTime , stateProofHash , proposer , validators , gasAmountTotal , gasCostTotal ) ;
367378 }
368379}
369380
0 commit comments