44import java .util .Iterator ;
55import java .util .Map ;
66import java .util .Map .Entry ;
7+ import lombok .extern .slf4j .Slf4j ;
78import org .tron .core .capsule .AccountCapsule ;
89import org .tron .core .capsule .AssetIssueCapsule ;
910import org .tron .core .capsule .ExchangeCapsule ;
1011import org .tron .core .db .Manager ;
1112
12-
13+ @ Slf4j
1314public class AssetUpdateHelper {
1415
1516 private Manager dbManager ;
@@ -21,11 +22,13 @@ public AssetUpdateHelper(Manager dbManager) {
2122 }
2223
2324 public void doWork () {
25+ logger .info ("Start to update the asset" );
2426 init ();
2527 updateAsset ();
2628 updateExchange ();
2729 updateAccount ();
2830 finish ();
31+ logger .info ("Complete the asset update" );
2932 }
3033
3134 public void init () {
@@ -47,6 +50,8 @@ public void updateAsset() {
4750 tokenIdNum ++;
4851 }
4952
53+ logger .info ("Complete the asset store update" );
54+
5055 }
5156
5257 public void updateExchange () {
@@ -59,10 +64,14 @@ public void updateExchange() {
5964 dbManager .getExchangeV2Store ().put (exchangeCapsule .createDbKey (), exchangeCapsule );
6065 }
6166
67+ logger .info ("Complete the exchange store update" );
68+
6269 }
6370
6471 public void updateAccount () {
6572
73+ long count = 0 ;
74+
6675 Iterator <Entry <byte [], AccountCapsule >> iterator = dbManager .getAccountStore ().iterator ();
6776 while (iterator .hasNext ()) {
6877 AccountCapsule accountCapsule = iterator .next ().getValue ();
@@ -71,15 +80,23 @@ public void updateAccount() {
7180 assetV2Map .put (new String (assetNameToIdMap .get (entry .getKey ())), entry .getValue ());
7281 }
7382
83+ accountCapsule .clearAssetV2 ();
7484 accountCapsule .addAssetV2Map (assetV2Map );
7585 dbManager .getAccountStore ().put (accountCapsule .createDbKey (), accountCapsule );
7686
87+ if (count % 50000 == 0 ) {
88+ logger .info ("The number of accounts that have completed the update :{}" , count );
89+ }
90+ count ++;
7791 }
7892
93+ logger .info ("Complete the account store update" );
94+
7995 }
8096
8197 public void finish () {
8298 dbManager .getDynamicPropertiesStore ().saveTokenUpdateDone (1 );
99+ assetNameToIdMap .clear ();
83100 }
84101
85102
0 commit comments