Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Added Error handling #43

Merged
merged 4 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions aptos-tx-latency-measurement/sendtx_aptos.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ function loadConfig() {
}

async function sendSlackMsg(msg) {
axios.post(
await axios.post(
process.env.SLACK_API_URL,
{
channel: process.env.SLACK_CHANNEL,
Expand Down Expand Up @@ -182,7 +182,7 @@ async function sendTx() {

if (balance < parseFloat(process.env.BALANCE_ALERT_CONDITION_IN_APTOS)) {
const now = new Date();
sendSlackMsg(
await sendSlackMsg(
`${now}, Current balance of <${process.env.SCOPE_URL}/address/${address}|${address}> is less than ${process.env.BALANCE_ALERT_CONDITION_IN_APTOS} APTOS! balance=${balance} APTOS`
);
}
Expand Down Expand Up @@ -229,7 +229,7 @@ async function sendTx() {
} catch (err) {

const now = new Date();
sendSlackMsg(`${now}, failed to execute aptos, ${err.toString()}`);
await sendSlackMsg(`${now}, failed to execute aptos, ${err.toString()}`);
console.log("failed to execute.", err.toString());
data.error = err.toString();
console.log(`${data.executedAt},${data.chainId},${data.txhash},${data.startTime},${data.endTime},${data.latency},${data.txFee},${data.txFeeInUSD},${data.resourceUsedOfLatestBlock},${data.numOfTxInLatestBlock},${data.pingTime},${data.error}`)
Expand All @@ -238,7 +238,7 @@ async function sendTx() {
await uploadChoice(data);
} catch (err) {
const now = new Date();
sendSlackMsg(`${now}, failed to upload aptos, ${err.toString()}`);
await sendSlackMsg(`${now}, failed to upload aptos, ${err.toString()}`);
console.log(
`failed to ${process.env.UPLOAD_METHOD === "AWS" ? "s3" : "gcs"}.upload!! Printing instead!`,
err.toString()
Expand All @@ -262,11 +262,24 @@ async function main() {

// run sendTx every SEND_TX_INTERVAL
const interval = eval(process.env.SEND_TX_INTERVAL);
setInterval(() => {
console.log(`sending tx...`);
sendTx();
}, interval);
sendTx();

setInterval(async()=>{
try{
await sendTx()
} catch(err){
console.log("failed to execute sendTx", err.toString())
}
}, interval)
try{
await sendTx()
} catch(err){
console.log("failed to execute sendTx", err.toString())
}
}
loadConfig();
main();
try{
main()
}
catch(err){
console.log("failed to execute main", err.toString())
}
40 changes: 27 additions & 13 deletions arbitrium-tx-latency-measurement/sendtx_arbitrium.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async function makeParquetFile(data) {
}

async function sendSlackMsg(msg) {
axios.post(
await axios.post(
process.env.SLACK_API_URL,
{
channel: process.env.SLACK_CHANNEL,
Expand Down Expand Up @@ -182,7 +182,7 @@ async function sendTx() {

if (balance < parseFloat(process.env.BALANCE_ALERT_CONDITION_IN_ARB)) {
const now = new Date();
sendSlackMsg(
await sendSlackMsg(
`${now}, Current balance of <${process.env.SCOPE_URL}/address/${signer.address}|${signer.address}> is less than ${process.env.BALANCE_ALERT_CONDITION_IN_ARB} ARB! balance=${balance} ARB`
);
}
Expand Down Expand Up @@ -262,7 +262,7 @@ async function sendTx() {
// console.log(`${data.executedAt},${data.chainId},${data.txhash},${data.startTime},${data.endTime},${data.latency},${data.txFee},${data.txFeeInUSD},${data.resourceUsedOfLatestBlock},${data.numOfTxInLatestBlock},${data.pingTime},${data.error}`)
} catch (err) {
const now = new Date();
sendSlackMsg(`${now}, failed to execute arbitrum, ${err.toString()}`);
await sendSlackMsg(`${now}, failed to execute arbitrum, ${err.toString()}`);
console.log("failed to execute.", err.toString());
data.error = err.toString();
// console.log(`${data.executedAt},${data.chainId},${data.txhash},${data.startTime},${data.endTime},${data.latency},${data.txFee},${data.txFeeInUSD},${data.resourceUsedOfLatestBlock},${data.numOfTxInLatestBlock},${data.pingTime},${data.error}`)
Expand All @@ -271,7 +271,7 @@ async function sendTx() {
await uploadChoice(data);
} catch (err) {
const now = new Date();
sendSlackMsg(`${now}, failed to upload arbitrium, ${err.toString()}`);
await sendSlackMsg(`${now}, failed to upload arbitrium, ${err.toString()}`);

console.log(
`failed to ${process.env.UPLOAD_METHOD === "AWS" ? "s3" : "gcs"}.upload!! Printing instead!`,
Expand Down Expand Up @@ -319,10 +319,10 @@ async function l1commitmentprocess(db, hash, createdAt) {
if (postIndex !== -1) {
console.log("L1 tx hash not found");
db.data.posts[postIndex].status = "failed";
sendSlackMsg(`L1 tx hash not found for ${hash} in Arbitrium!`);
await sendSlackMsg(`L1 tx hash not found for ${hash} in Arbitrium!`);
return null;
} else {
sendSlackMsg(`l2 ${hash} not found in Arbitrium!`);
await sendSlackMsg(`l2 ${hash} not found in Arbitrium!`);
return Error("l2TxHash not found.");
}
}
Expand All @@ -338,7 +338,7 @@ async function l1commitmentprocess(db, hash, createdAt) {
gcpData.hash = hash;
uploadToGCSL1(gcpData)
} else {
sendL1FailedSlackMsg(`l2 ${hash} not found! in Arbitrium!`);
await sendSlackMsg(`l2 ${hash} not found! in Arbitrium!`);
return Error("l2TxHash not found.");
}
}
Expand All @@ -359,11 +359,25 @@ async function main() {

// run sendTx every SEND_TX_INTERVAL
const interval = eval(process.env.SEND_TX_INTERVAL);
setInterval(() => {
sendTx();
l1Checker();
}, interval);
sendTx();
setInterval(async()=>{
try{
await sendTx()
await l1Checker();
} catch(err){
console.log("failed to execute sendTx", err.toString())
}
}, interval)
try{
await sendTx()
} catch(err){
console.log("failed to execute sendTx", err.toString())
}
}

main();

try{
main()
}
catch(err){
console.log("failed to execute main", err.toString())
}
34 changes: 25 additions & 9 deletions avalanche-tx-latency-measurement/sendtx_avalanche.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ async function makeParquetFile(data) {
}

async function sendSlackMsg(msg) {
axios.post(process.env.SLACK_API_URL, {
await axios.post(process.env.SLACK_API_URL, {
'channel':process.env.SLACK_CHANNEL,
'mrkdown':true,
'text':msg
Expand Down Expand Up @@ -164,7 +164,7 @@ const sendAvax = async (amount, to, maxFeePerGas = undefined, maxPriorityFeePerG
if(balance < parseFloat(process.env.BALANCE_ALERT_CONDITION_IN_AVAX))
{
const now = new Date();
sendSlackMsg(`${now}, Current balance of <${process.env.SCOPE_URL}/address/${address}|${address}> is less than ${process.env.BALANCE_ALERT_CONDITION_IN_AVAX} AVAX! balance=${balance} AVAX`)
await sendSlackMsg(`${now}, Current balance of <${process.env.SCOPE_URL}/address/${address}|${address}> is less than ${process.env.BALANCE_ALERT_CONDITION_IN_AVAX} AVAX! balance=${balance} AVAX`)
}

const latestNonce = await HTTPSProvider.getTransactionCount(address);
Expand Down Expand Up @@ -233,15 +233,15 @@ const sendAvax = async (amount, to, maxFeePerGas = undefined, maxPriorityFeePerG
// console.log(`${data.executedAt},${data.chainId},${data.txhash},${data.startTime},${data.endTime},${data.latency},${data.txFee},${data.txFeeInUSD},${data.resourceUsedOfLatestBlock},${data.numOfTxInLatestBlock},${data.pingTime},${data.error}`)
} catch(err){
const now = new Date();
sendSlackMsg(`${now}, failed to execute avalanche, ${err.toString()}`);
await sendSlackMsg(`${now}, failed to execute avalanche, ${err.toString()}`);
console.log("failed to execute.", err.toString())
data.error = err.toString()
// console.log(`${data.executedAt},${data.chainId},${data.txhash},${data.startTime},${data.endTime},${data.latency},${data.txFee},${data.txFeeInUSD},${data.resourceUsedOfLatestBlock},${data.numOfTxInLatestBlock},${data.pingTime},${data.error}`)
}
try{
await uploadChoice(data)
} catch(err){
sendSlackMsg(`failed to upload avalanche, ${err.toString()}`);
await sendSlackMsg(`failed to upload avalanche, ${err.toString()}`);
console.log(`failed to ${process.env.UPLOAD_METHOD === 'AWS'? 's3': 'gcs'}.upload!! Printing instead!`, err.toString())
console.log(JSON.stringify(data))
}
Expand All @@ -264,11 +264,27 @@ async function main(){
address = wallet.address;

// run sendTx every SEND_TX_INTERVAL(sec).



const interval = eval(process.env.SEND_TX_INTERVAL)
setInterval(()=>{
sendAvax("0.0", address);

setInterval(async()=>{
try{
await sendAvax("0.0", address);
} catch(err){
console.log("failed to execute sendTx", err.toString())
}
}, interval)
sendAvax("0.0", address);
try{
await sendAvax("0.0", address);
} catch(err){
console.log("failed to execute sendTx", err.toString())
}
}

main();
try{
main()
}
catch(err){
console.log("failed to execute main", err.toString())
}
29 changes: 21 additions & 8 deletions bnb-tx-latency-measurement/sendtx_bnb.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ async function makeParquetFile(data) {
}

async function sendSlackMsg(msg) {
axios.post(process.env.SLACK_API_URL, {
await axios.post(process.env.SLACK_API_URL, {
'channel':process.env.SLACK_CHANNEL,
'mrkdown':true,
'text':msg
Expand Down Expand Up @@ -142,7 +142,7 @@ async function sendTx(){
if(balance < parseFloat(process.env.BALANCE_ALERT_CONDITION_IN_BNB))
{
const now = new Date();
sendSlackMsg(`${now}, Current balance of <${process.env.SCOPE_URL}/address/${signer.address}|${signer.address}> is less than ${process.env.BALANCE_ALERT_CONDITION_IN_BNB} BNB! balance=${balance} BNB`)
await sendSlackMsg(`${now}, Current balance of <${process.env.SCOPE_URL}/address/${signer.address}|${signer.address}> is less than ${process.env.BALANCE_ALERT_CONDITION_IN_BNB} BNB! balance=${balance} BNB`)
}

await web3.eth.net.getId().then((id)=>{
Expand Down Expand Up @@ -216,15 +216,15 @@ async function sendTx(){

} catch(err){
const now = new Date();
sendSlackMsg(`${now}, failed to execute bnb, ${err.toString()}`);
await sendSlackMsg(`${now}, failed to execute bnb, ${err.toString()}`);
console.log("failed to execute.", err.toString())
data.error = err.toString()
// console.log(`${data.executedAt},${data.chainId},${data.txhash},${data.startTime},${data.endTime},${data.latency},${data.txFee},${data.txFeeInUSD},${data.resourceUsedOfLatestBlock},${data.numOfTxInLatestBlock},${data.pingTime},${data.error}`)
}
try{
await uploadChoice(data)
} catch(err){
sendSlackMsg(`failed to upload bnb, ${err.toString()}`);
await sendSlackMsg(`failed to upload bnb, ${err.toString()}`);
console.log(`failed to ${process.env.UPLOAD_METHOD === 'AWS'? 's3': 'gcs'}.upload!! Printing instead!`, err.toString())
console.log(JSON.stringify(data))
}
Expand All @@ -244,10 +244,23 @@ async function main(){

// run sendTx every SEND_TX_INTERVAL
const interval = eval(process.env.SEND_TX_INTERVAL)
setInterval(()=>{
sendTx()
setInterval(async()=>{
try{
await sendTx()
} catch(err){
console.log("failed to execute sendTx", err.toString())
}
}, interval)
sendTx()
try{
await sendTx()
} catch(err){
console.log("failed to execute sendTx", err.toString())
}
}

main();
try{
main()
}
catch(err){
console.log("failed to execute main", err.toString())
}
29 changes: 21 additions & 8 deletions elrond-tx-latency-measurement/sendtx_elrond.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async function makeParquetFile(data) {
}

async function sendSlackMsg(msg) {
axios.post(process.env.SLACK_API_URL, {
await axios.post(process.env.SLACK_API_URL, {
'channel':process.env.SLACK_CHANNEL,
'mrkdown':true,
'text':msg
Expand Down Expand Up @@ -146,7 +146,7 @@ async function sendTx(){
if(balance < parseFloat(process.env.BALANCE_ALERT_CONDITION_IN_EGLD))
{
const now = new Date();
sendSlackMsg(`${now}, Current balance of <${process.env.SCOPE_URL}/accounts/${address.toString()}|${address.toString()}> is less than ${process.env.BALANCE_ALERT_CONDITION_IN_EGLD} EGLD! balance=${balance} EGLD`)
await sendSlackMsg(`${now}, Current balance of <${process.env.SCOPE_URL}/accounts/${address.toString()}|${address.toString()}> is less than ${process.env.BALANCE_ALERT_CONDITION_IN_EGLD} EGLD! balance=${balance} EGLD`)
}

const networkConfig = await networkProvider.getNetworkConfig();
Expand Down Expand Up @@ -234,15 +234,15 @@ async function sendTx(){

} catch(err){
const now = new Date();
sendSlackMsg(`${now}, failed to execute elrond, ${err.toString()}`);
await sendSlackMsg(`${now}, failed to execute elrond, ${err.toString()}`);
console.log("failed to execute.", err.toString())
data.error = err.toString()
// console.log(`${data.executedAt},${data.chainId},${data.txhash},${data.startTime},${data.endTime},${data.latency},${data.txFee},${data.txFeeInUSD},${data.resourceUsedOfLatestBlock},${data.numOfTxInLatestBlock},${data.pingTime},${data.error}`)
}
try{
await uploadToS3(data)
} catch(err){
sendSlackMsg(`failed to upload elrond, ${err.toString()}`);
await sendSlackMsg(`failed to upload elrond, ${err.toString()}`);
console.log('failed to s3.upload! Printing instead!', err.toString())
console.log(JSON.stringify(data))
}
Expand Down Expand Up @@ -270,10 +270,23 @@ async function main(){

// run sendTx every SEND_TX_INTERVAL
const interval = eval(process.env.SEND_TX_INTERVAL)
setInterval(()=>{
sendTx()
setInterval(async()=>{
try{
await sendTx()
} catch(err){
console.log("failed to execute sendTx", err.toString())
}
}, interval)
sendTx()
try{
await sendTx()
} catch(err){
console.log("failed to execute sendTx", err.toString())
}
}

main();
try{
main()
}
catch(err){
console.log("failed to execute main", err.toString())
}
Loading
Loading