Renewing the Certificate for RPC Node (Ngnix Server)

The RPC Node https://api.justyy.com is expiring in 5 days.

expiring-certificate.jpg

Nowadays, you can easily get a free SSL certificate but you have to manually/automatically renew it every 90 days.

To apply for a certificate, you have to verify your domain - either by email of your domain, place a file on your server (which can be public accessed), or modify the DNS record.

If your DNS has configured CAA records, you need to remove them or add specific records allowing a SSL provider to issue the certificates on your domain.

Once the certificates are issued, you will see the following files:

certificates.jpg

You need to combine two CRTs into one:

1
cat certificate.crt ca_bundle.crt >> certificate.crt

Then in Nginx server, add the following in server block:

1
2
3
4
listen   443;
ssl on;
ssl_certificate /etc/ssl/certificate.crt;
ssl_certificate_key /etc/ssl/private.key;

Last but not least, restart the nginx server.

1
2
3
sudo /etc/init.d/nginx restart
# or
sudo service nginx restart

image.png


Every little helps! I hope this helps!

Steem On!~

Reposted to Blog

If you like my work, please consider voting for me, thanks!
https://steemit.com/~witnesses type in justyy and click VOTE



Alternatively, you could proxy to me if you are too lazy to vote!

Also: you can vote me at the tool I made: https://steemyy.com/witness-voting/?witness=justyy

Visit me at: https://steemyy.com


This page is synchronized from the post: ‘Renewing the Certificate for RPC Node (Ngnix Server)’

Design: How to Solve 503 Error of API when Resources are not available?

The HTTP 503 Error indidicates the server is busy. It might be due to the fact that the servers are overloaded (high load average).

One of my API is designed to return 503 Error when the cached file is not available. It is designed as the follows:

1
2
3
4
if (!is_file($file)) {
throw_503();
die();
}

The $file will be updated periodically e.g. every minute via Crontab. When the OS is writing to that file, the is_file will return false because the file is in-use.

One way of solving this is to have multiple caching versions, to avoid the single point of failure. For example, if a file-1 is not available we can check for file-2. These two files should not be updated at the same time.

Another way to resolve this issue is to add a delay check (hacky solution), for example:

1
2
3
4
5
6
7
if (!is_file($file)) {
sleep(1); // delay check.
}
if (!is_file($file)) {
throw_503();
die();
}

Every little helps! I hope this helps!

Steem On!~

*Reposted to Blog

If you like my work, please consider voting for me, thanks!
https://steemit.com/~witnesses type in justyy and click VOTE



Alternatively, you could proxy to me if you are too lazy to vote!

Also: you can vote me at the tool I made: https://steemyy.com/witness-voting/?witness=justyy

Visit me at: https://steemyy.com


This page is synchronized from the post: ‘Design: How to Solve 503 Error of API when Resources are not available?’

A Bug in the SteemJs Regarding the Incorrect Reputation

Current SteemJs Library has a bug in computing the reputation. I have raised this two years ago and proposed a fix

Specifically:

1
2
console.log(steem.formatter.reputation(10004392664120));
console.log(steem.formatter.reputation(10004392664120+100000000000));

As you will see this output:

1
2
70
61

Which is incorrect. The problem is at the code L166

Here, the developer probably didn’t know the Math.log10 function can be used to compute the Log10, instead, he/she uses a math trick Math.log(x)/Math.log(10) to compute the Math.log10 based on natural logarithm (base e ).

This will introduce rounding errors, and sometimes intermediate results will be amplified leading to much bigger errors.

1
2
console.log(Math.log10(1000))
console.log(Math.log(1000)/Math.log(10))

This will output

1
2
3
2.9999999999999996

In Line 168, it uses parseInt, therefore, the difference will be becoming ONE.

There are a few fixes:

  1. change parseInt to Math.round
  2. change entirely to use Math.log10
  3. or completely rewriting this function, as my PR (approved by @ety001 thanks!, but not merged yet due to this is a legacy PR which was created more than 2 years ago and the main branch has differed a lot).
    https://github.com/steemit/steem-js/pull/345/files

image.png

If you are happening to rely on this function, you probably need to do it yourself until this fix is merged.


Every little helps! I hope this helps!

Steem On!~

If you like my work, please consider voting for me, thanks!
https://steemit.com/~witnesses type in justyy and click VOTE



Alternatively, you could proxy to me if you are too lazy to vote!

Also: you can vote me at the tool I made: https://steemyy.com/witness-voting/?witness=justyy

Visit me at: https://steemyy.com


This page is synchronized from the post: ‘A Bug in the SteemJs Regarding the Incorrect Reputation’

SteemJs Programming: What Happens on the Steem Blockchain in the Last 24 Hours?

Many questions are interesting but the answers are not obvious or easy to get. For example: Who comments most in the last 24 hours?

I am going to show you a pattern to find out the answers to such questions using SteemJs.

Get Current Lastest Block

We need to get the latest block number on the steem blockchain, and we can work out roughly the last 24 hours block range by subtracting 206024 (3 seconds a block).

1
2
3
4
5
6
7
8
9
10
11
function getBlockchainData() {
return new Promise((resolve, reject) => {
steem.api.getDynamicGlobalProperties(function(err, result) {
if (!err) {
resolve(result);
} else {
reject(err);
}
});
});
}

The current block number is:

1
2
const blockchain = await getBlockchainData();
const maxBlock = blockchain.head_block_number;

Getting the Block Content

Each block contains transactions, here you would need to parse the list of transactions and look for the particular ones that you are interested. For example, if we want to compute the total producer rewards by witnesses, we can look for “producer_reward”.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
function getBlock(block) {
return new Promise((resolve, reject) => {
steem.api.getOpsInBlock(block, false, function(err, result) {
if (!err) {
const txCount = result.filter(x=>x.virtual_op===0).length;
const producer = result.filter(x=>x.op[0] === "producer_reward");
const witness = producer[0].op[1].producer;
const reward = producer[0].op[1].vesting_shares;
resolve({
count: txCount,
witness: witness,
reward: reward.replace(" VESTS", ""),
time: producer[0].timestamp.replace("T", " ")
});
} else {
reject(err);
}
});
});
}

Writing to Database or a File

We need to write the data into a database, or for simplicity, we can write to a CSV file for later process.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
(async function() {
const blockchain = await getBlockchainData();
const maxBlock = blockchain.head_block_number;
for (let block = maxBlock - 20*60*24; block <= maxBlock; ++ block) {
try {
const data = await getBlock(block);
const s = '"' + data.time + '",' + block + ',"' + data.witness + '",' + data.count + "," + data.reward + "\n";
log(s);
fs.appendFileSync('data.csv', s);
} catch (e) {
log(e);
}
}
})();

Of course, if you want to further develop into a tool, you would need a database, and a background daemon that automatically syncs with the blockchain.


Every little helps! I hope this helps!

Steem On!~

Reposted to Blog

If you like my work, please consider voting for me, thanks!
https://steemit.com/~witnesses type in justyy and click VOTE



Alternatively, you could proxy to me if you are too lazy to vote!

Also: you can vote me at the tool I made: https://steemyy.com/witness-voting/?witness=justyy

Visit me at: https://steemyy.com


This page is synchronized from the post: ‘SteemJs Programming: What Happens on the Steem Blockchain in the Last 24 Hours?’

New Tool: Steem Witness Update Tool

Added another tool to broadcast witness update:

Tool URL: https://steemyy.com/witness-update/
Chinese: https://steemyy.com/witness-update-tool/

What this tool can do for you?

Usually, I send update using the conductor directly on my witness server. But sometimes when you are not able to SSH, this tool would be handy.

Click “Get Witness Information” which will retrieve the current Witness Data and populate in the fields.
image.png

A friendly advice: Set Signing Key to STM1111111111111111111111111111111114T1Anm to take your witness offline if you are not able to make it! (to avoid missing blocks and be voted out)


Every little helps! I hope this helps!

Steem On!~

If you like my work, please consider voting for me, thanks!
https://steemit.com/~witnesses type in justyy and click VOTE



Alternatively, you could proxy to me if you are too lazy to vote!

Also: you can vote me at the tool I made: https://steemyy.com/witness-voting/?witness=justyy

Visit me at: https://steemyy.com


This page is synchronized from the post: ‘New Tool: Steem Witness Update Tool’

How to Set Up Your On-Call Duty when Your Witness is Missing a Block?

What is On-Call? You know many Software Engineers at Big Companies need to do On-Call Duties to fix service related issues when they arise.

Yesterday, I presented a utility to switch your node in case of missing too many blocks. But wouldn’t it be a lot nicer if we can be notified (be paged) when this happens?

Please be warned that if you like less intrusive notification, you should go for SMS (which should be easy to set up using the method below) or even just email.

Post: Open Source: Auto Switch Your Witness Node In the Event of Failure
Open Source Utility: https://github.com/DoctorLai/SteemWitnessAutoSwitch

This is how we can set up the on-call when missing blocks.

IFTTT

You may have heard of IFTTT which stands for If This Then That. This is a powerful service that allows you to connect two or more services.

First, you would need to register a IFTTT account, then you would need to connect the “Webhooks” service which allows you to send a message to the hook. Then, the “That” part would be to connect the “Voip Call” part which will call you - alternatively, you could choose other notification methods such as SMS or Emails, or even make a tweet if you like!

image.png

image.png

image.png

image.png

This is how the final recipe looks like:

image.png

Note that we can pass a value1 parameter to report the current missing blocks.
Here is how you send a notification message to the webhook aka “This”

curl -X POST -H “Content-Type: application/json” -d ‘{“value1”:”123”}’ https://maker.ifttt.com/trigger/{steem-witness}/with/key/YourIFTTTKeyHere

You will see this message on success.
Congratulations! You’ve fired the steem-witness event

Then, on the github code https://github.com/DoctorLai/SteemWitnessAutoSwitch/blob/master/monitor-witness.js , you can modify a little bit:

1
2
3
4
5
6
7
8
const execSync = require('child_process').execSync;

function reportMissing(missed) {
log("Report missing: " + missed);
// TODO: You can send a email/SMS here
execSync('curl -X POST -H "Content-Type: application/json" -d \'{"value1":"' + missed + '"}\'
https://maker.ifttt.com/trigger/{steem-witness}/with/key/YourIFTTTKeyHere');
}

That is it, everytime there is a missing block, you will get a call who will tell you total missed blocks aka the parameter value1

image.png

image.png

image.png


Every little helps! I hope this helps!

Steem On!~

Repost to Blog

If you like my work, please consider voting for me, thanks!
https://steemit.com/~witnesses type in justyy and click VOTE



Alternatively, you could proxy to me if you are too lazy to vote!

Also: you can vote me at the tool I made: https://steemyy.com/witness-voting/?witness=justyy

Visit me at: https://steemyy.com


This page is synchronized from the post: ‘How to Set Up Your On-Call Duty when Your Witness is Missing a Block?’

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×