Skip to content

Commit

Permalink
Merge pull request #713 from signum-network/feat/fast-rollback
Browse files Browse the repository at this point in the history
Feat/fast rollback
  • Loading branch information
jjos2372 committed Dec 29, 2022
2 parents 9c02733 + 95608db commit d7a621a
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 3 deletions.
22 changes: 22 additions & 0 deletions resources/db/migration_h2/V7_9__rollback_indices.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
CREATE INDEX IF NOT EXISTS account_height_idx ON account(height);
CREATE INDEX IF NOT EXISTS account_balance_height_idx ON account_balance(height);
CREATE INDEX IF NOT EXISTS account_asset_height_idx ON account_asset(height);

CREATE INDEX IF NOT EXISTS indirect_incoming_height_idx ON indirect_incoming(height);

CREATE INDEX IF NOT EXISTS alias_height_idx ON alias(height);
CREATE INDEX IF NOT EXISTS alias_offer_height_idx ON alias_offer(height);

CREATE INDEX IF NOT EXISTS asset_height_idx ON asset(height);
CREATE INDEX IF NOT EXISTS asset_transfer_height_idx ON asset_transfer(height);
CREATE INDEX IF NOT EXISTS ask_order_height_idx ON ask_order(height);
CREATE INDEX IF NOT EXISTS bid_order_height_idx ON bid_order(height);
CREATE INDEX IF NOT EXISTS trade_height_idx ON trade(height);

CREATE INDEX IF NOT EXISTS at_height_idx ON at(height);
CREATE INDEX IF NOT EXISTS at_state_height_idx ON at_state(height);
CREATE INDEX IF NOT EXISTS at_map_height_idx ON at_map(height);

CREATE INDEX IF NOT EXISTS subscription_height_idx ON subscription(height);

CREATE INDEX IF NOT EXISTS reward_recip_assign_height_idx ON reward_recip_assign(height);
22 changes: 22 additions & 0 deletions resources/db/migration_mariadb/V7_9__rollback_indices.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
CREATE INDEX IF NOT EXISTS account_height_idx ON account(height);
CREATE INDEX IF NOT EXISTS account_balance_height_idx ON account_balance(height);
CREATE INDEX IF NOT EXISTS account_asset_height_idx ON account_asset(height);

CREATE INDEX IF NOT EXISTS indirect_incoming_height_idx ON indirect_incoming(height);

CREATE INDEX IF NOT EXISTS alias_height_idx ON alias(height);
CREATE INDEX IF NOT EXISTS alias_offer_height_idx ON alias_offer(height);

CREATE INDEX IF NOT EXISTS asset_height_idx ON asset(height);
CREATE INDEX IF NOT EXISTS asset_transfer_height_idx ON asset_transfer(height);
CREATE INDEX IF NOT EXISTS ask_order_height_idx ON ask_order(height);
CREATE INDEX IF NOT EXISTS bid_order_height_idx ON bid_order(height);
CREATE INDEX IF NOT EXISTS trade_height_idx ON trade(height);

CREATE INDEX IF NOT EXISTS at_height_idx ON at(height);
CREATE INDEX IF NOT EXISTS at_state_height_idx ON at_state(height);
CREATE INDEX IF NOT EXISTS at_map_height_idx ON at_map(height);

CREATE INDEX IF NOT EXISTS subscription_height_idx ON subscription(height);

CREATE INDEX IF NOT EXISTS reward_recip_assign_height_idx ON reward_recip_assign(height);
5 changes: 4 additions & 1 deletion src/brs/BlockchainProcessorImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,10 @@ private List<Block> popOffTo(Block commonBlock, List<Block> forkBlocks) {
block = popLastBlock();
}
logger.debug("Rolling back derived tables...");
derivedTableManager.getDerivedTables().forEach(table -> table.rollback(commonBlock.getHeight()));
for(DerivedTable table : derivedTableManager.getDerivedTables()) {
logger.debug("Rolling back {}", table.getTable());
table.rollback(commonBlock.getHeight());
}
dbCacheManager.flushCache();
stores.commitTransaction();
downloadCache.resetCache();
Expand Down
2 changes: 1 addition & 1 deletion src/brs/Burst.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

public final class Burst {

public static final Version VERSION = Version.parse("v3.5.2");
public static final Version VERSION = Version.parse("v3.5.3");
public static final String APPLICATION = "BRS";

public static final String CONF_FOLDER = "./conf";
Expand Down
2 changes: 1 addition & 1 deletion src/brs/BurstGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ private TrayIcon createTrayIcon() {
}

openPheonixWalletItem.addActionListener(e -> openWebUi("/phoenix"));
openClassicWalletItem.addActionListener(e -> openWebUi("/classic.html"));
openClassicWalletItem.addActionListener(e -> openWebUi("/classic"));
showItem.addActionListener(e -> showWindow());
shutdownItem.addActionListener(e -> shutdown());

Expand Down
2 changes: 2 additions & 0 deletions src/brs/db/DerivedTable.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package brs.db;

public interface DerivedTable extends Table {
String getTable();

void rollback(int height);

void truncate();
Expand Down
5 changes: 5 additions & 0 deletions src/brs/db/sql/DerivedSqlTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ public abstract class DerivedSqlTable implements DerivedTable {
this.heightField = tableClass.field("height", Integer.class);
this.latestField = tableClass.field("latest", Boolean.class);
}

@Override
public String getTable() {
return table;
}

@Override
public void rollback(int height) {
Expand Down

0 comments on commit d7a621a

Please sign in to comment.