7575import io .xdag .utils .WalletUtils ;
7676import io .xdag .utils .XdagTime ;
7777import java .math .BigInteger ;
78- import java .util .ArrayList ;
79- import java .util .LinkedHashMap ;
80- import java .util .List ;
81- import java .util .Map ;
82- import java .util .Objects ;
83- import java .util .Set ;
78+ import java .util .*;
8479import java .util .concurrent .ConcurrentHashMap ;
8580import java .util .concurrent .ScheduledExecutorService ;
8681import java .util .concurrent .ScheduledFuture ;
@@ -768,11 +763,7 @@ private UInt64 applyBlock(Block block) {
768763 if (link .getType () == XdagField .FieldType .XDAG_FIELD_IN ) {
769764 subtractAndAccept (ref ,link .getAmount ());
770765 UInt64 allBalance = addressStore .getAllBalance ();
771- try {
772- allBalance = allBalance .addExact (link .getAmount ());
773- }catch (Exception e ){
774- log .debug ("apply allBalance error" );
775- }
766+ allBalance = allBalance .add (link .getAmount ());
776767 addressStore .updateAllBalance (allBalance );
777768 } else {
778769 addAndAccept (ref ,link .getAmount ());
@@ -796,6 +787,7 @@ private UInt64 applyBlock(Block block) {
796787 // TODO: unapply block which in snapshot
797788 public UInt64 unApplyBlock (Block block ) {
798789 List <Address > links = block .getLinks ();
790+ Collections .reverse (links );
799791 if ((block .getInfo ().flags & BI_APPLIED ) != 0 ) {
800792 UInt64 sum = UInt64 .ZERO ;
801793 for (Address link : links ) {
@@ -1495,7 +1487,9 @@ public void startCheckMain(long period) {
14951487 }
14961488
14971489 public void checkState () {
1498- checkOrphan ();
1490+ if (kernel .getXdagState () == XdagState .SDST || XdagState .STST == kernel .getXdagState () || XdagState .SYNC == kernel .getXdagState ()) {
1491+ checkOrphan ();
1492+ }
14991493 checkMain ();
15001494 }
15011495
@@ -1561,7 +1555,7 @@ private void addAndAccept(Block block, UInt64 amount) {
15611555 try {
15621556 block .getInfo ().setAmount (block .getInfo ().getAmount ().addExact (amount ));
15631557 } catch (Exception e ) {
1564- // log.error(e.getMessage(), e);
1558+ log .error (e .getMessage (), e );
15651559 log .debug ("balance {} amount {} block {}" , oldAmount , amount , block .getHashLow ().toHexString ());
15661560 }
15671561 UInt64 finalAmount = blockStore .getBlockInfoByHash (block .getHashLow ()).getInfo ().getAmount ();
@@ -1583,7 +1577,7 @@ private void subtractAndAccept(Block block,UInt64 amount){
15831577 try {
15841578 block .getInfo ().setAmount (block .getInfo ().getAmount ().subtractExact (amount ));
15851579 } catch (Exception e ) {
1586- // log.error(e.getMessage(), e);
1580+ log .error (e .getMessage (), e );
15871581 log .debug ("balance {} amount {} block {}" , oldAmount , amount , block .getHashLow ().toHexString ());
15881582 }
15891583 UInt64 finalAmount = blockStore .getBlockInfoByHash (block .getHashLow ()).getInfo ().getAmount ();
@@ -1605,7 +1599,7 @@ private void subtractAmount(byte[] addressHash, UInt64 amount, Block block){
16051599 try {
16061600 addressStore .updateBalance (addressHash ,balance .subtractExact (amount ));
16071601 } catch (Exception e ) {
1608- // log.error(e.getMessage(), e);
1602+ log .error (e .getMessage (), e );
16091603 log .debug ("balance {} amount {} addressHsh {} block {}" , balance , amount , toBase58 (addressHash ), block .getHashLow ());
16101604 }
16111605 UInt64 finalAmount = addressStore .getBalanceByAddress (addressHash );
@@ -1623,11 +1617,11 @@ private void addAmount(byte[] addressHash, UInt64 amount, Block block){
16231617 try {
16241618 addressStore .updateBalance (addressHash ,balance .addExact (amount ));
16251619 } catch (Exception e ) {
1626- // log.error(e.getMessage(), e);
1620+ log .error (e .getMessage (), e );
16271621 log .debug ("balance {} amount {} addressHsh {} block {}" , balance , amount , toBase58 (addressHash ), block .getHashLow ());
16281622 }
16291623 UInt64 finalAmount = addressStore .getBalanceByAddress (addressHash );
1630- log .debug ("Balance checker —— Address:{} [old:{} add:{} fin:{}]" ,
1624+ log .warn ("Balance checker —— Address:{} [old:{} add:{} fin:{}]" ,
16311625 WalletUtils .toBase58 (addressHash ),
16321626 BasicUtils .amount2xdag (balance ),
16331627 BasicUtils .amount2xdag (amount ),
@@ -1645,7 +1639,7 @@ private void acceptAmount(Block block, UInt64 amount) {
16451639 blockStore .saveBlockInfo (block .getInfo ());
16461640 }
16471641 UInt64 finalAmount = blockStore .getBlockByHash (block .getHashLow (),false ).getInfo ().getAmount ();
1648- log .debug ("Balance checker —— Block:{} [old:{} acc:{} fin:{}]" ,
1642+ log .warn ("Balance checker —— Block:{} [old:{} acc:{} fin:{}]" ,
16491643 block .getHashLow ().toHexString (),
16501644 BasicUtils .amount2xdag (oldAmount ),
16511645 BasicUtils .amount2xdag (amount ),
0 commit comments