Skip to content

Commit

Permalink
rescue added
Browse files Browse the repository at this point in the history
  • Loading branch information
gluk64 committed May 16, 2019
1 parent 7c1624a commit 15c995a
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 4 deletions.
11 changes: 7 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ loadtest: confirm_action
prepare-loadtest: confirm_action
@node js/loadtest/loadtest.js prepare

rescue: confirm_action
@node js/loadtest/rescue.js

# Devops: main

# (Re)deploy contracts and database
Expand All @@ -175,14 +178,14 @@ dockerhub-push: image-nginx image-rust
apply-kubeconfig:
@bin/k8s-apply

restart-kube-rust: apply-kubeconfig
update-rust: push-image-rust apply-kubeconfig
@kubectl patch deployment $(FRANKLIN_ENV)-server -p "{\"spec\":{\"template\":{\"metadata\":{\"labels\":{\"date\":\"$(shell date +%s)\"}}}}}"
@kubectl patch deployment $(FRANKLIN_ENV)-prover -p "{\"spec\":{\"template\":{\"metadata\":{\"labels\":{\"date\":\"$(shell date +%s)\"}}}}}"

update-nginx: push-image-nginx apply-kubeconfig
@kubectl patch deployment $(FRANKLIN_ENV)-nginx -p "{\"spec\":{\"template\":{\"metadata\":{\"labels\":{\"date\":\"$(shell date +%s)\"}}}}}"

start-kube: push-image-nginx push-image-rust apply-kubeconfig restart-kube-rust restart-kube-nginx
start-kube: push-image-nginx push-image-rust apply-kubeconfig update-rust update-nginx

ifeq (,$(KUBECONFIG))
start: image-nginx image-rust start-local
Expand Down Expand Up @@ -211,7 +214,7 @@ log:
ifeq (,$(KUBECONFIG))
@docker-compose logs -f server prover
else
kubectl logs -f deployments/server
kubectl logs -f deployments/$(FRANKLIN_ENV)-server
endif


Expand All @@ -224,7 +227,7 @@ nodes:
kubectl get nodes -o wide

proverlogs:
kubectl logs -f deployments/prover
kubectl logs -f deployments/$(FRANKLIN_ENV)-prover


# Dev environment
Expand Down
65 changes: 65 additions & 0 deletions js/loadtest/rescue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
const ethers = require('ethers')

const bn = ethers.utils.bigNumberify;

const gasPriceScaling = bn(20);

async function rescue() {
console.log("This is intended to run on mainnet only!");
const web3Url = process.env.WEB3_URL;
let privateKey = process.env.PRIVATE_KEY;

// const web3Url = "http://localhost:8545";
// let privateKey = "27593fea79697e947890ecbecce7901b0008345e5d7259710d0dd5e500d040be";
if (privateKey === undefined || web3Url === undefined) {
console.log("Missing private key or web3 URL in environment");
return;
}
if (! privateKey.startsWith("0x")) {
privateKey = "0x" + privateKey;
}
const provider = new ethers.providers.JsonRpcProvider(web3Url);
const source = new ethers.Wallet(privateKey, provider);
const address = source.address;
source.connect(provider);

let gasPrice = await provider.getGasPrice();
console.log("Current gas price is " + gasPrice.div(bn(1000000000)).toString() + " GWei");

gasPrice = gasPrice.mul(gasPriceScaling);

let latestNonce = await provider.getTransactionCount(address, "latest");
let pendingNonce = await provider.getTransactionCount(address, "pending");

if (latestNonce === pendingNonce) {
console.log("No transactions to replace");
return;
}

for (let i = latestNonce; i <= pendingNonce; i++) {
console.log("Replacing nonce = " + i);
try {
let result = await source.sendTransaction(
{
to: address,
nonce: i,
gasPrice: gasPrice,
gasLimit: 21000,
}
);
console.log("Successfully send with hash " + result.hash);
console.log("Used gas price " + gasPrice.div(bn(1000000000)).toString() + " GWei and limit 21000");
} catch(error) {
if (error.transactionHash !== undefined) {
console.log("There may have been a network erro sending transaction, replacements hash = " + error.transactionHash);
} else {
console.log(error);
}
}
}

}

rescue().then(() => {
console.log("Done");
});

0 comments on commit 15c995a

Please sign in to comment.