Skip to content

Commit

Permalink
Merge pull request #16 from Beldex-Coin/Hardfork-version-updated
Browse files Browse the repository at this point in the history
  • Loading branch information
codeman-crypto authored Dec 23, 2023
2 parents b2301b7 + e92dc51 commit 2b73de0
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 98 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "bchat-desktop",
"productName": "BChat",
"description": "Private messaging from your desktop",
"version": "2.1.0",
"version": "2.1.1",
"license": "GPL-3.0",
"author": {
"name": "Beldex team",
Expand Down
26 changes: 13 additions & 13 deletions preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ window.Signal = data.initData();
// Linux seems to periodically let the event loop stop, so this is a global workaround
setInterval(() => {
// tslint:disable-next-line: no-empty
window.nodeSetImmediate(() => {});
window.nodeSetImmediate(() => { });
}, 1000);

window.React = require('react');
Expand All @@ -241,15 +241,15 @@ if (window.networkType == 'mainnet') {
window.getSeedNodeList = () =>
process.env.NODE_ENV == 'development'
? [
'https://publicnode1.rpcnode.stream:443',
'https://publicnode2.rpcnode.stream:443',
'https://publicnode3.rpcnode.stream:443',
]
'https://publicnode1.rpcnode.stream:443',
'https://publicnode2.rpcnode.stream:443',
'https://publicnode3.rpcnode.stream:443',
]
: [
'https://publicnode1.rpcnode.stream:443',
'https://publicnode2.rpcnode.stream:443',
'https://publicnode3.rpcnode.stream:443',
];
'https://publicnode1.rpcnode.stream:443',
'https://publicnode2.rpcnode.stream:443',
'https://publicnode3.rpcnode.stream:443',
];

const remotes = [
{
Expand Down Expand Up @@ -294,18 +294,18 @@ if (window.networkType == 'mainnet') {
} else {
window.getSeedNodeList = () =>
process.env.NODE_ENV == 'development'
? ['http://38.242.196.72:19095', 'http://154.26.139.105:19095']
: ['http://38.242.196.72:19095', 'http://154.26.139.105:19095'];
? ['http://149.102.156.174:19095']
: ['http://149.102.156.174:19095'];

const remotes = [
{
host: '38.242.196.72',
host: '149.102.156.174',
port: '19095',
active: 0,
type: 'Remote',
},
{
host: '154.26.139.105',
host: '149.102.156.174',
port: '19095',
active: 0,
type: 'Remote',
Expand Down
80 changes: 40 additions & 40 deletions ts/bchat/apis/snode_api/hfHandling.ts
Original file line number Diff line number Diff line change
@@ -1,71 +1,71 @@
import { isNumber } from 'lodash';
import { createOrUpdateItem, getItemById } from '../../../data/channelsItem';

let hasSeenHardfork190: boolean | undefined;
let hasSeenHardfork191: boolean | undefined;
let hasSeenHardfork170: boolean | undefined;
let hasSeenHardfork180: boolean | undefined;

/**
* this is only intended for testing. Do not call this in production.
*/
export function resetHardForkCachedValues() {
hasSeenHardfork190 = hasSeenHardfork191 = undefined;
hasSeenHardfork170 = hasSeenHardfork180 = undefined;
}

export async function getHasSeenHF190() {
if (hasSeenHardfork190 === undefined) {
export async function getHasSeenHF170() {
if (hasSeenHardfork170 === undefined) {
// read values from db and cache them as it looks like we did not
const oldHhasSeenHardfork190 = (await getItemById('hasSeenHardfork190'))?.value;
const oldHhasSeenHardfork170 = (await getItemById('hasSeenHardfork170'))?.value;
// values do not exist in the db yet. Let's store false for now in the db and update our cached value.
if (oldHhasSeenHardfork190 === undefined) {
await createOrUpdateItem({ id: 'hasSeenHardfork190', value: false });
hasSeenHardfork190 = false;
if (oldHhasSeenHardfork170 === undefined) {
await createOrUpdateItem({ id: 'hasSeenHardfork170', value: false });
hasSeenHardfork170 = false;
} else {
hasSeenHardfork190 = oldHhasSeenHardfork190;
hasSeenHardfork170 = oldHhasSeenHardfork170;
}
}
return hasSeenHardfork190;
return hasSeenHardfork170;
}

export async function getHasSeenHF191() {
if (hasSeenHardfork191 === undefined) {
export async function getHasSeenHF180() {
if (hasSeenHardfork180 === undefined) {
// read values from db and cache them as it looks like we did not
const oldHhasSeenHardfork191 = (await getItemById('hasSeenHardfork191'))?.value;
const oldHhasSeenHardfork180 = (await getItemById('hasSeenHardfork180'))?.value;

// values do not exist in the db yet. Let's store false for now in the db and update our cached value.
if (oldHhasSeenHardfork191 === undefined) {
await createOrUpdateItem({ id: 'hasSeenHardfork191', value: false });
hasSeenHardfork191 = false;
if (oldHhasSeenHardfork180 === undefined) {
await createOrUpdateItem({ id: 'hasSeenHardfork180', value: false });
hasSeenHardfork180 = false;
} else {
hasSeenHardfork191 = oldHhasSeenHardfork191;
hasSeenHardfork180 = oldHhasSeenHardfork180;
}
}
return hasSeenHardfork191;
return hasSeenHardfork180;
}

export async function handleHardforkResult(json: Record<string, any>) {
if (hasSeenHardfork190 === undefined || hasSeenHardfork191 === undefined) {
if (hasSeenHardfork170 === undefined || hasSeenHardfork180 === undefined) {
// read values from db and cache them as it looks like we did not
const oldHhasSeenHardfork190 = (await getItemById('hasSeenHardfork190'))?.value;
const oldHasSeenHardfork191 = (await getItemById('hasSeenHardfork191'))?.value;
const oldHhasSeenHardfork170 = (await getItemById('hasSeenHardfork170'))?.value;
const oldHasSeenHardfork180 = (await getItemById('hasSeenHardfork180'))?.value;

// values do not exist in the db yet. Let's store false for now in the db and update our cached value.
if (oldHhasSeenHardfork190 === undefined) {
await createOrUpdateItem({ id: 'hasSeenHardfork190', value: false });
hasSeenHardfork190 = false;
if (oldHhasSeenHardfork170 === undefined) {
await createOrUpdateItem({ id: 'hasSeenHardfork170', value: false });
hasSeenHardfork170 = false;
} else {
hasSeenHardfork190 = oldHhasSeenHardfork190;
hasSeenHardfork170 = oldHhasSeenHardfork170;
}
if (oldHasSeenHardfork191 === undefined) {
await createOrUpdateItem({ id: 'hasSeenHardfork191', value: false });
hasSeenHardfork191 = false;
if (oldHasSeenHardfork180 === undefined) {
await createOrUpdateItem({ id: 'hasSeenHardfork180', value: false });
hasSeenHardfork180 = false;
} else {
hasSeenHardfork191 = oldHasSeenHardfork191;
hasSeenHardfork180 = oldHasSeenHardfork180;
}
}

if (hasSeenHardfork191 && hasSeenHardfork190) {
if (hasSeenHardfork180 && hasSeenHardfork170) {
// no need to do any of this if we already know both forks happened
window.log.info('hardfork 19.1 already happened. No need to go any further');
window.log.info('hardfork 18.0 already happened. No need to go any further');
return;
}

Expand All @@ -77,15 +77,15 @@ export async function handleHardforkResult(json: Record<string, any>) {
isNumber(json.hf[0]) &&
isNumber(json.hf[1])
) {
if (!hasSeenHardfork190 && json.hf[0] >= 19 && json.hf[1] >= 0) {
window.log.info('[HF]: We just detected HF 19.0 on "retrieve"');
await createOrUpdateItem({ id: 'hasSeenHardfork190', value: true });
hasSeenHardfork190 = true;
if (!hasSeenHardfork170 && json.hf[0] >= 17 && json.hf[1] >= 0) {
window.log.info('[HF]: We just detected HF 17.0 on "retrieve"');
await createOrUpdateItem({ id: 'hasSeenHardfork170', value: true });
hasSeenHardfork170 = true;
}
if (!hasSeenHardfork191 && json.hf[0] >= 19 && json.hf[1] >= 1) {
window.log.info('[HF]: We just detected HF 19.1 on "retrieve"');
await createOrUpdateItem({ id: 'hasSeenHardfork191', value: true });
hasSeenHardfork191 = true;
if (!hasSeenHardfork180 && json.hf[0] >= 18 && json.hf[1] >= 0) {
window.log.info('[HF]: We just detected HF 18.0 on "retrieve"');
await createOrUpdateItem({ id: 'hasSeenHardfork180', value: true });
hasSeenHardfork180 = true;
}
}
}
6 changes: 3 additions & 3 deletions ts/bchat/apis/snode_api/swarmPolling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { perfEnd, perfStart } from '../../utils/Performance';
import { ed25519Str } from '../../onions/onionPath';
import { updateIsOnline } from '../../../state/ducks/onion';
import pRetry from 'p-retry';
import { getHasSeenHF190, getHasSeenHF191 } from './hfHandling';
import { getHasSeenHF170, getHasSeenHF180 } from './hfHandling';

interface Message {
hash: string;
Expand Down Expand Up @@ -163,8 +163,8 @@ export class SwarmPolling {
?.idForLogging() || group.pubkey.key;

if (diff >= convoPollingTimeout) {
const hardfork190Happened = await getHasSeenHF190();
const hardfork191Happened = await getHasSeenHF191();
const hardfork190Happened = await getHasSeenHF170();
const hardfork191Happened = await getHasSeenHF180();
window?.log?.info(
`Polling for ${loggingId}; timeout: ${convoPollingTimeout}; diff: ${diff} ; hardfork190Happened: ${hardfork190Happened}; hardfork191Happened: ${hardfork191Happened} `
);
Expand Down
6 changes: 3 additions & 3 deletions ts/bchat/sending/MessageSender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { getConversationController } from '../conversations';
import { ed25519Str } from '../onions/onionPath';
import { EmptySwarmError } from '../utils/errors';
import ByteBuffer from 'bytebuffer';
import { getHasSeenHF190, getHasSeenHF191 } from '../apis/snode_api/hfHandling';
import { getHasSeenHF170, getHasSeenHF180 } from '../apis/snode_api/hfHandling';

const DEFAULT_CONNECTIONS = 1;

Expand Down Expand Up @@ -141,8 +141,8 @@ export async function sendMessageToSnode(
const conversation = getConversationController().get(pubKey);
const isClosedGroup = conversation?.isClosedGroup();

const hardfork190Happened = await getHasSeenHF190();
const hardfork191Happened = await getHasSeenHF191();
const hardfork190Happened = await getHasSeenHF170();
const hardfork191Happened = await getHasSeenHF180();
const namespace = isClosedGroup ? -10 : 0;

window?.log?.debug(
Expand Down
Loading

0 comments on commit 2b73de0

Please sign in to comment.