diff --git a/plugins/src/main/java/org/tron/plugins/DbCompare.java b/plugins/src/main/java/org/tron/plugins/DbCompare.java index 9f7c5fbca6..5b093205dd 100644 --- a/plugins/src/main/java/org/tron/plugins/DbCompare.java +++ b/plugins/src/main/java/org/tron/plugins/DbCompare.java @@ -11,6 +11,7 @@ import org.tron.plugins.utils.db.DBInterface; import org.tron.plugins.utils.db.DBIterator; import org.tron.plugins.utils.db.DbTool; +import org.tron.protos.Protocol; import picocli.CommandLine; @Slf4j(topic = "compare") @@ -33,6 +34,8 @@ public class DbCompare implements Callable { @CommandLine.Option(names = {"-h", "--help"}, help = true, description = "display a help message") private boolean help; + private static final String ACCOUNT_VOTE_SUFFIX = "-account-vote"; + @Override public Integer call() throws Exception { if (help) { @@ -98,7 +101,7 @@ private boolean compare() throws RocksDBException, IOException { byte[] baseKey = baseIterator.getKey(); byte[] dstKey = dstIterator.getKey(); byte[] dstValue = dstIterator.getValue(); - if (Arrays.equals(baseKey, dstKey) && !Arrays.equals(baseValue, dstValue)) { + if (Arrays.equals(baseKey, dstKey) && !compareValue(baseKey, baseValue, dstValue)) { spec.commandLine().getOut().format("%s\t%s\t%s.", ByteArray.toHexString(baseKey), ByteArray.toHexString(baseValue), ByteArray.toHexString(dstValue)).println(); @@ -109,7 +112,7 @@ private boolean compare() throws RocksDBException, IOException { if (!Arrays.equals(baseKey, dstKey)) { byte[] dstValueTmp = base.get(dstKey); byte[] baseValueTmp = dst.get(baseKey); - if (!Arrays.equals(baseValue, baseValueTmp)) { + if (!compareValue(baseKey, baseValue, baseValueTmp)) { spec.commandLine().getOut().format("%s\t%s\t%s.", ByteArray.toHexString(baseKey), ByteArray.toHexString(baseValue), ByteArray.toHexString(baseValueTmp)).println(); @@ -117,7 +120,7 @@ private boolean compare() throws RocksDBException, IOException { ByteArray.toHexString(baseKey), ByteArray.toHexString(baseValue), ByteArray.toHexString(baseValueTmp)); } - if (!Arrays.equals(dstValueTmp, dstValue)) { + if (!compareValue(dstKey, dstValueTmp, dstValue)) { spec.commandLine().getOut().format("%s\t%s\t%s.", ByteArray.toHexString(dstKey), ByteArray.toHexString(dstValueTmp), ByteArray.toHexString(dstValue)).println(); @@ -132,7 +135,7 @@ private boolean compare() throws RocksDBException, IOException { byte[] key = baseIterator.getKey(); byte[] baseValue = baseIterator.getValue(); byte[] destValue = dst.get(key); - if (!Arrays.equals(baseValue, destValue)) { + if (!compareValue(key, baseValue, destValue)) { spec.commandLine().getOut().format("%s\t%s\t%s.", ByteArray.toHexString(key), ByteArray.toHexString(baseValue), ByteArray.toHexString(destValue)).println(); @@ -145,7 +148,7 @@ private boolean compare() throws RocksDBException, IOException { byte[] key = dstIterator.getKey(); byte[] destValue = dstIterator.getValue(); byte[] baseValue = base.get(key); - if (!Arrays.equals(baseValue, destValue)) { + if (!compareValue(key, baseValue, destValue)) { spec.commandLine().getOut().format("%s\t%s\t%s.", ByteArray.toHexString(key), ByteArray.toHexString(baseValue), ByteArray.toHexString(destValue)).println(); @@ -159,5 +162,24 @@ private boolean compare() throws RocksDBException, IOException { spec.commandLine().getOut().println("compare " + this.name + " end"); return true; } + + private boolean compareValue(byte[] key, byte[] base, byte[] exp) { + if ("account".equals(name) + || ("delegation".equals(name) && new String(key).endsWith(ACCOUNT_VOTE_SUFFIX))) { + Protocol.Account baseAccount = ByteArray.toAccount(base); + Protocol.Account expAccount = ByteArray.toAccount(exp); + if (baseAccount.getAssetOptimized()) { + baseAccount = baseAccount.toBuilder().clearAsset().clearAssetV2().build(); + } + if (expAccount.getAssetOptimized()) { + expAccount = expAccount.toBuilder().clearAsset().clearAssetV2().build(); + } + // remove assetOptimized // TODO why? + return baseAccount.toBuilder().clearAssetOptimized().build() + .equals(expAccount.toBuilder().clearAssetOptimized().build()); + } else { + return Arrays.equals(base, exp); + } + } } }