@@ -595,7 +595,21 @@ public void pushBlock(final BlockCapsule block)
595595 }
596596
597597 public void updateDynamicProperties (BlockCapsule block ) {
598+ long slot = 1 ;
599+ if (block .getNum () != 1 ){
600+ slot = getSlotAtTime (block .getTimeStamp ());
601+ }
602+ for (int i = 1 ; i < slot ; ++i ){
603+ if (!getScheduledWitness (i ).equals (block .getWitnessAddress ())){
604+ WitnessCapsule w = this .witnessStore .get (createDbKey (getScheduledWitness (i )));
605+ w .setTotalMissed (w .getTotalMissed ()+1 );
606+ this .witnessStore .put (w .createDbKey (), w );
607+ logger .info ("{} miss a block. totalMissed = {}" ,
608+ w .createReadableString (), w .getTotalMissed ());
609+ }
610+ }
598611 this .head = block ;
612+ logger .info ("update head, num = {}" , block .getNum ());
599613 this .dynamicPropertiesStore
600614 .saveLatestBlockHeaderHash (block .getBlockId ().getByteString ());
601615 this .dynamicPropertiesStore .saveLatestBlockHeaderNumber (block .getNum ());
@@ -885,30 +899,34 @@ private void processMaintenance(BlockCapsule block) {
885899
886900 /**
887901 * @param block the block update signed witness. set witness who signed block the 1. the latest
888- * block num 2. pay the trx to witness. 3. (TODO) the latest slot num.
902+ * block num 2. pay the trx to witness. 3. the latest slot num.
889903 */
890904
891905 public void updateSignedWitness (BlockCapsule block ) {
892906 //TODO: add verification
893907 WitnessCapsule witnessCapsule = witnessStore
894908 .get (block .getInstance ().getBlockHeader ().getRawData ().getWitnessAddress ().toByteArray ());
895- long latestSlotNum = 0 ;
896- witnessCapsule .getInstance (). toBuilder (). setLatestBlockNum (block .getNum ())
897- .setLatestSlotNum (latestSlotNum )
898- . build ();
899- AccountCapsule sun = accountStore . getSun ( );
909+ witnessCapsule . setTotalProduced ( witnessCapsule . getTotalProduced ()+ 1 ) ;
910+ witnessCapsule .setLatestBlockNum (block .getNum ());
911+ witnessCapsule .setLatestSlotNum (getAbSlotAtTime ( block . getTimeStamp ()));
912+
913+ this . getWitnessStore (). put ( witnessCapsule . getAddress (). toByteArray (), witnessCapsule );
900914
915+ AccountCapsule sun = accountStore .getSun ();
901916 try {
902917 adjustBalance (sun .getAddress ().toByteArray (), -WITNESS_PAY_PER_BLOCK );
903918 } catch (BalanceInsufficientException e ) {
904-
919+ logger . debug ( e . getMessage (), e );
905920 }
906921 try {
907922 adjustBalance (witnessCapsule .getAddress ().toByteArray (), WITNESS_PAY_PER_BLOCK );
908923 } catch (BalanceInsufficientException e ) {
909924 logger .debug (e .getMessage (), e );
910925 }
911926
927+ logger .info ("updateSignedWitness. witness address:{}, blockNum:{}, totalProduced:{}" ,
928+ witnessCapsule .createReadableString (), block .getNum (), witnessCapsule .getTotalProduced ());
929+
912930 }
913931
914932 private long blockInterval () {
0 commit comments