Skip to content

Commit

Permalink
Merge pull request #521 from pinheadmz/hsdv4
Browse files Browse the repository at this point in the history
Upgrade hsd to v4.0.0 with chainDB migration and tree compaction
  • Loading branch information
rithvikvibhu committed Jun 26, 2022
2 parents 67b63d6 + 71e512b commit db36ca4
Show file tree
Hide file tree
Showing 7 changed files with 540 additions and 269 deletions.
19 changes: 17 additions & 2 deletions app/background/node/service.js
Expand Up @@ -23,6 +23,7 @@ import {
SET_SPV_MODE,
START_NODE_STATUS_CHANGE,
END_NODE_STATUS_CHANGE,
COMPACTING_TREE,
} from "../../ducks/nodeReducer";
import pkg from '../../../package.json';

Expand Down Expand Up @@ -231,20 +232,34 @@ export class NodeService extends EventEmitter {
nsPort: 9891,
noDns: this.noDns,
listen: this.networkName === 'regtest', // improves remote rpc dev/testing
chainMigrate: 2,
chainMigrate: 3,
walletMigrate: 1,
maxOutbound: 4,
compactTreeOnInit: true,
});

this.hsd.use(plugin);

this.hsd.on('tree compact start', () => {
dispatchToMainWindow({
type: COMPACTING_TREE,
payload: true,
});
});
this.hsd.on('tree compact end', () => {
dispatchToMainWindow({
type: COMPACTING_TREE,
payload: false,
});
});

await this.hsd.ensure();
await this.hsd.open();
this.emit('start local', this.hsd.get('walletdb'), walletApiKey);
await this.hsd.connect();
await this.hsd.startSync();

const migrateFlag = `${this.networkName}-hsd-3.0.0-migrate${spv ? '-spv' : ''}`;
const migrateFlag = `${this.networkName}-hsd-4.0.0-migrate${spv ? '-spv' : ''}`;

if (!(await get(migrateFlag))) {
await put(migrateFlag, true);
Expand Down
63 changes: 47 additions & 16 deletions app/components/SplashScreen/index.js
Expand Up @@ -14,6 +14,7 @@ class SplashScreen extends Component {
error: Proptype.string,
network: Proptype.string,
spv: Proptype.bool,
compactingTree: Proptype.bool,
};

static defaultProps = {
Expand All @@ -23,14 +24,19 @@ class SplashScreen extends Component {
static contextType = I18nContext;

state = {
hasMigrated300: false,
hasMigrated400: false,
};

async componentWillMount() {
// TODO: `network` is ALWAYS 'main' here. I think that is because
// this code runs before any of the background stuff has a chance
// to update state with user's actual configuration. This is only an
// issue for developers because we will see the splash screen for a moment
// on every boot in regtest until state.network is updated.
const {network, spv} = this.props;
const migrateFlag = `${network}-hsd-3.0.0-migrate${spv ? '-spv' : ''}`;
const hasMigrated300 = await dbClient.get(migrateFlag);
this.setState({ hasMigrated300 });
const migrateFlag = `${network}-hsd-4.0.0-migrate${spv ? '-spv' : ''}`;
const hasMigrated400 = await dbClient.get(migrateFlag);
this.setState({ hasMigrated400 });
}

render() {
Expand All @@ -49,31 +55,56 @@ class SplashScreen extends Component {
<React.Fragment>
<div style={spinnerStyle} />
<div style={textStyles}>{t('splashLoading')}</div>
{
!this.state.hasMigrated300 && (
<Alert type="warning" style={alertStyle}>
<div>
{t('splashMigrate3001')}
</div>
<div>
{t('splashMigrate3002')}
</div>
</Alert>
)
}
{ this.renderAlert(t) }
</React.Fragment>
)
}
</div>
);
}

renderAlert(t) {
// Tree compaction alert takes precedence
if (this.props.compactingTree) {
return (
<Alert type="warning" style={alertStyle}>
<div>
{t('compactingTree1')}
</div>
<div>
{t('compactingTree2')}
</div>
</Alert>
);
}

if (!this.state.hasMigrated400) {
return(
<Alert type="warning" style={alertStyle}>
<div>
{
// Technically the version is now 4.0.0 not 3.0.0
// but the atual text in the message is version
// agnostic ("migration in progress...")
// so we can probably just leave this as is.
t('splashMigrate3001')
}
</div>
<div>
{t('splashMigrate3002')}
</div>
</Alert>
)
}
}
}

export default withRouter(
connect(
(state) => ({
network: state.node.network,
spv: state.node.spv,
compactingTree: state.node.compactingTree,
}),
)(SplashScreen)
);
Expand Down
7 changes: 7 additions & 0 deletions app/ducks/nodeReducer.js
Expand Up @@ -18,6 +18,7 @@ export const SET_RS_PORT = 'node/SET_RS_PORT';
export const SET_NS_PORT = 'node/SET_NS_PORT';
export const SET_NO_DNS = 'node/SET_NO_DNS';
export const SET_SPV_MODE = 'node/SET_SPV_MODE';
export const COMPACTING_TREE = 'node/COMPACTING_TREE';

export function getInitialState() {
return {
Expand All @@ -33,6 +34,7 @@ export function getInitialState() {
nsPort: 9891,
noDns: false,
spv: false,
compactingTree: false,
fees: {
slow: 0,
medium: 0,
Expand Down Expand Up @@ -136,6 +138,11 @@ export default function nodeReducer(state = getInitialState(), action = {}) {
...state,
spv: action.payload,
};
case COMPACTING_TREE:
return {
...state,
compactingTree: action.payload,
};
default:
return state;
}
Expand Down
2 changes: 2 additions & 0 deletions locales/XXXXX.json
Expand Up @@ -70,6 +70,8 @@
"closed": "XXXXX",
"closedAuctionTitle": "XXXXX",
"comingSoon": "XXXXX",
"compactingTree1": "XXXXX",
"compactingTree2": "XXXXX",
"confirmFee": "XXXXX",
"confirmReset": "XXXXX",
"createListing": "XXXXX",
Expand Down
2 changes: 2 additions & 0 deletions locales/en.json
Expand Up @@ -72,6 +72,8 @@
"closedAuctionTitle": "Domain is no longer available",
"collapse": "Collapse",
"comingSoon": "Coming Soon",
"compactingTree1": "Compacting Urkel Tree",
"compactingTree2": "Bob is deleting stale data to recover space on your disk. This will take several minutes. If Bob Wallet is closed during this process, it will start over on the next open. This process must be complete before proceeding to login screen.",
"confirmFee": "Confirm Fee",
"confirmReset": "Confirm Reset",
"copy": "Copy",
Expand Down

0 comments on commit db36ca4

Please sign in to comment.