Getting Familiar with Some Cool Git Commands- git bisect & git blame

Reading Time: 5 minutes

So, this article will move around:

  1. git bisect
  2. git blame

So let’s discuss them one by one, with the situations in which they can be used.

Finding Regression Error using ‘git bisect’:

‘git bisect’ will work as a life-saver spell if you need to find a regression bug introduced in your software accidentally. Such type of errors are common in group projects or open-source, in which some contributor unintentionally changes certain important piece of code, which breaks some other functionality, and it remains unnoticed for a long period of time. So, when such bug comes under notice, the main task of the maintainer is to track when this bug/breakage is introduced or to say before which commit, all things were working correctly.

So, the general approach to this problem would be to find a commit at which things were working correctly, and perform a binary search between the good commit and the latest commit to find the commit at which things were broken. This will narrow down the consideration window with few rounds of compiling.

Of course, it is a perfect approach, but doing it manually and keeping an eye on the good and bad commit makes the process cumbersome. So here comes the ‘git bisect’ for rescue.

To find the bug, firstly checkout to master and handover the git the responsibility to find the regression bug by firing:

git bisect start

By the above command, before the git starts the process you need to give a reference to a bad-commit and a good commit.

Assuming things are bad at the current HEAD, for giving reference to a bad commit use:

git bisect bad HEAD

After that, to perform a binary search, a reference to a commit, where things were working as expected, is needed. So, just take the hash of good-commit and use:

git bisect good <git-hash>

After this stage, git will start the process to find the breakage point. It will automatically checkout to the intermediate commits. All you need to do is to mark the checked-out commit as good or bad by:

git bisect good
git bisect bad

 

Let’s see this with example. Consider the file:

In this file, at line-4 the correct word was ‘Blockchain’, but accidentally it has been changed. So let’s find out the commit, before which everything was good.

Here is the git-log for reference:

Let’s start the git bisect and as things were good at ‘add Blockchain’ commit. So let’s take it as a good commit and take the latest commit as bad commit.

You can see that git take over the task of divide and conquer, and also displays the rough steps remaining in finding the regression point. So, all you have to do now is to mark the current checked out commit as good or bad.

After seeing the file at ‘add compiler design’ commit, we can conclude it as a good commit, as the spelling is correct there. So, let’s mark it as good commit.

The next bisect point is a bad commit, so let’s mark it.

Again, it’s a bad commit.

Whoops, we just found the commit at which things the word was misspelt. It is the commit with the message ‘add MP’.

In the same way, you can find regression bugs very easily in big projects :).

It saved me many hours, so will also save yours.


Finding the culprit for breaking the code by ‘git blame’:

The official documentation says, git blame-

Annotates each line in the given file with information from the revision which last modified the line. Optionally, start annotating from the given revision.

So in short, it is used to find the person in a group project, who changed the line and responsible for breaking the project.

So, git blame command will give you the information about the latest commit that changed the line, for all the lines accompanied by the author of the commit.

Command:

So let’s try this out by :

git blame <path-to-file>

Clearly, you can see the latest commit hash which changed the Line-4. Although the author in these commits are same. But if it is a team project, you can also judge which person broke the code, so that you can blame him, to have a coffee :).

You can also use GitHub to find the git blame for a line:

 

Similarly, GitLab also has the option to view blames:

That’s all for this article and Don’t forget to ‘Clap’, if you have found it useful.

References:

https://git-scm.com/docs/git-blame

https://git-scm.com/docs/git-bisect

You can find some more good-stuff at:

GIT and GITHUB: A Layman’s Guide[Part-1]

GIT and GITHUB: A Layman’s Guide [Part-2]

The Byzantine Fault Tolerance

Reading Time: 5 minutes

This short-article focusses on one of the most popular consensus problems in distributed computing known as “Byzantine’s General Problem” and when a distributed system is said to be Byzantine Fault Tolerant.
Various Byzantine Fault Tolerant algorithms are being used in Permissioned Blockchain Networks e.g Hyperledger Sawtooth is using Practical Byzantine Fault Tolerant(PBFT) to achieve consensus. So, if you want to understand how the consensus is actually achieved in such systems. This article is surely for you.

So let’s begin this journey.

First of let’s focus on the term ‘Byzantine Fault Tolerant’ and when a distributed system is said to be Byzantine Fault Tolerant?
The answer lies within the different types of failures that can occur in a distributed system-

1.Crash-Fail: In this type of failure, the component stop working without any warning. So you need to restart the node or replace it. We can say it is a ‘Fail-Stop’ failure.

2.Omission Failure: In this, component transmits a message but that message is not received by other nodes or we can say it is omitted.

3.Byzantine Failures: It is a ‘no-stop failure’.It occurs when there is a malicious or traitor node in the network which sends conflicting messages or block the messages by not sending them to the other nodes in the network, which may lead to faulty results.

Now I think it is self-explanatory that a distributed system is said to be Byzantine Fault Tolerant if it can cope-up with the Byzantine Failures.

The applications of BFT can be found in various domain like Blockchain and even in Boeing 777 and 787 flight controls.

Let’s move on to a specific problem which forms a base for understanding BFT-

The Byzantine General’s Problem :

Situation: Suppose there are several generals and they have to attack army camp C and they are surrounding the army camp such that they can’t communicate with each other directly. The only way communication can happen in between them is through a carrier and he needs to pass the enemy camp for transferring every message.
So they need proper protocols to reach a final decision whether to “attack ” on C, the next morning or “retreat”.
If they all agree to attack, and they do attack then they will surely win or if they agree to “retreat” then they can fight on another day. But if one of the general attack and other decides to retreat then they are surely gonna lose.

Problems:

  • Malicious Generals create variation in the decision to the others
  • Message Carriers may not reach
  • Reach a single solution, considering the downsides of a few Generals

Keeping in mind the situation, let’s discuss this problem with three generals.

Three Generals Problem:

Suppose, there are one commander and two lieutenants surrounding the army camp C and they have to collectively reach a decision to ‘attack’ or ‘retreat’.

If neither of the generals is faulty then all will work good and they will surely reach a decision.

The Byzantine Fault Tolerance

 Let’s see the case if one of the generals starts behaving maliciously:

The Byzantine Fault Tolerance

Let’s break up the whole communication process in two phases.

Phase-1: Commander sends the messages correctly to lieutenants.

Phase-2: Lieutenant-1 correctly forwards the message to Lieutenant-2.
As Lieutenant-2 is malicious, so he forwards the message to Lieutenant-1 incorrectly.

Clearly, Lieutenant-1 is receiving differing messages.

Let’s take a look at another possibility before jumping onto the conclusion.

What will be the case if ‘Commander’ is faulty?

The Byzantine Fault Tolerance

Phase-1: Lieutenant-1 and Lieutenant-2 recieves different messages.

Phase-2: They both exchange the messages correctly as they are loyal.

As per the protocols, both Lieutenants have to follow the Commander’s message. This is in the contradiction of the agreement condition.

Conclusion: There is no solution possible for ‘Three Generals Problem’ if one of the generals is faulty.

Four Generals Problem

Suppose, there are one commander and three lieutenants surrounding the army camp C and they have to collectively reach a decision to ‘attack’ or ‘retreat’.

When one of the Lieutenant is faulty?

The Byzantine Fault Tolerance

Phase-1: Commander correctly sends the message to other lieutenants.

Phase-2: Lieutenant-1 & Lieutenant-3 correctly forwards the message to others.
Lieutenant-2 behaves in a byzantine manner and incorrectly transmits the message.

By Majority Voting, the non-malicious lieutenants can reach the decision.

Decision of Lieutenant-1:
Majority(Retreat,Attack,Retreat)=Retreat

Decision of Lieutenant-2:
Majority(Retreat,Retreat,Attack)= Retreat

So, they have reached the consensus i.e “To Retreat”.

When the Commander is faulty?

The Byzantine Fault Tolerance

I think you can deduce what will happen in the two phases now.
Jumping directly to the decisions:-

Decision of Lieutenant-1:
Majority(Retreat,Attack,Retreat)=Retreat

Decision of Lieutenant-2:
Majority(Attack,Retreat,Retreat)= Retreat

Decision of Lieutenant-3:
Majority(Retreat,Retreat,Attack)=Retreat

So, the consensus has been achieved with the decision “To Retreat”.

One more special thing to observe here is that the final agreement will be the one which is in the majority of the decisions in Phase-1 e.g Retreat is in majority in Phase-1. So final agreement is on “Retreat‘’.

Conclusion: If out of 4 generals, only one is faulty or behaving in a byzantine way, then we can reach the agreement and consensus is achieved.

By the above two scenarios, we can now generalise the Byzantine Model of Distributed Systems.

Generalization

A System having ‘f’ number of faulty nodes(generals) should have at least, in total 3f+1 nodes(generals) in the network to reach the consensus.

Thanks for showing patience and reading until the end.

Next in the series is ‘PBFT & RBFT Consensus’ and ‘Consensus in Public Blockchain Networks’.

References:
https://people.eecs.berkeley.edu/~luca/cs174/byzantine.pdf

CIRCADIAN RHYTHM : The Inner Engineering

Reading Time: 6 minutes

So, first of all, I want to share the motivation behind the topic. The Nobel prize of 2017 in Physiology (medicine) was shared by three American scientists Jeffrey C. Hall, Michael Rosbash and Michael W. Young for the discovery of molecular mechanism behind Circadian Rhythm.

CIRCADIAN RHYTHM : The Inner Engineering

For introduction: Circadian Rhythm is phenomena that leads all biological process to display an oscillation of about 24 hours and work in sync with each other for optimum health. These rhythms are tuned by a circadian clock and apply to nearly all the organisms. In simple words, the routine of our anatomy is controlled by a body clock.

Here is the proof that the clock is genetically controlled :

There was an experiment in which a healthy adult was shifted to an underground apartment for 40 days to check whether he could maintain his sleep-wake cycle without the aid of sunlight or any external means.

Here is are the recordings of his sleep-wake cycle –

CIRCADIAN RHYTHM : The Inner Engineering

Blue represents wake and yellow represents sleep. As the days go on only sleeping timing moves towards midnight but the time period of sleep almost remain constant, hence it can be easily deduced that time-period of body clock is not altered by external factors, the time period remains close to 24 hrs. It has taken decade-long medical researchers to establish that genes control the circadian clock.

Here is what happens in our body to maintain sleep-wake cycle-

If it is assumed that the circadian clock rightly synchronized to earth day and night then it will make you go to sleep by 11 o’clock, will reach deep sleep by 3 o’clock and to anticipate waking body will begin warming up at around 5 o’clock, as soon as you wake up the hormone called melatonin hurtle down and stress hormone called cortisol will rise, brain will reach its peak performance time by noon, athletic performance get its peak in late afternoon and as evening sets the level of melatonin again begin to increase and by 11 o’clock sufficient melatonin is acquired to get a sound sleep.

CIRCADIAN RHYTHM : The Inner Engineering

So humans and other organism developed their body clock in synchronization to day-night cycle i.e. 24 hrs as of our planet earth to anticipate daily life. Evolution of body clocks took place through developing adaptation to external stimuli of warm, bright days and cool, dark nights, through genes. And we all must be feel thankful for inheriting this life-sustaining feature by virtue of our primitives or past generations. In the coming part of the blog, I will prove to you how this gift can be taped to become the healthiest version of ourselves, maximize our productivity and do greater feats.

HOW GENES WORK?

Now every cell in our body has the 24-hour cycle and here is how it operates.

This video beautifully explains the molecular mechanism of the genes to run the body clock.

Till now we have an overview of how the circadian clock works now let’s talk how do we relate this with our lives after all an engineer is far more interested in practical applications and theory behind.CIRCADIAN RHYTHM : The Inner Engineering

We have seen that the time period of this clock is 24 hours but point to be noted is that every organ in our body has its own cycle and work in sync with cycle of other organs to form a single system like blood supply to liver peaks in midnight during deep sleep, lungs gets its peak blood supply in early morning, large intestine in late morning, and so on, so what we need to take care is that this synchronization among organs of body system remain in harmony as they are very well subjected to external stimuli.

HOW LIGHT AFFECTS THIS SYNCHRONICITY?

CIRCADIAN RHYTHM : The Inner Engineering

Basically the clock of our brain, the master clock, gets activated by blue light, if natural cycle is followed the blue color rich light of morning sunset melatonin to lowest, as the evening sets the natural light becomes less rich in blue and appears red and orange, for which our master clock has evolved to response by instructing to increase melatonin. Now problem is that most part of day-time we live indoors the light of which is not rich in blue color and brains receives a confusing signal, at night when we use our electronic gadgets blue light content is much more than outside hence again a confusing signal and hence melatonin is not controlled properly. If continued for longer duration give rise to problems like migraine, ASD, ADHD, Depression, etc. This is the reason why comps people get sleep late in night and these days devices, when operated at night mode, shifts its color to orange, eliminating blue. On the other hand, owls have evolved to respond differently.

HOW FOOD AFFECT SYNCHRONICITY?

CIRCADIAN RHYTHM : The Inner Engineering

Normal functioning of the digestive system is as follows- during the day time our body runs on carbohydrates provided by diet and stores fats, at night time no carbohydrates input is there and hence body works on fat. Consider if you give carbohydrates to the body at late night then the body cannot burn the fats, hence chances of becoming obese are increased. The solution to this problem is that eat the same amount of food you generally do but avoid taking input late night, it will surely hammer on circadian rhythm by offsetting stomach from the sync with the system.

Now the last part of the blog, the healing power of circadian rhythm. So you must have noticed that the medicines prescribed to you are also instructed to be taken at a particular time of day. The circadian clock tunes the potency of every drug we take, so taking the drug at the instructed time of day can cure you as well as taking it at the wrong time can have adverse effects also. Schedule of flu shots, surgery of liver or heart, radiation therapy of cancer patients all these things depends on the time of day.

Conclusion: We can analyze that in earlier days human died due to diseases like malaria, dengue, chickenpox, polio, pneumonia, mumps, rabies, Ebola, etc. until proper sanitation, vaccination, and antibiotics came into existence, but now the scenario has changed. Now, most common diseases are chronic kidney diseases, asthma, hypertension, anxiety, diabetes, lung cancer, breast cancer, liver cancer, insomnia, bipolar, acid reflux, etc. These diseases are directly or indirectly related with our ignorant attitude towards our lifestyles and to be more precise hampering the Circadian Rhythm has bought this havoc to us.

In the end, thanks for time and patience and whole CEV team wishes you a happy Diwali.

Stay healthy, Enjoy reading!

Regards,

TEAM CEV.

What is API?

Reading Time: 5 minutes

-By Hrishabh Sharma

Overview

Here are some definitions of API from various resources:

“In computer programming, an application programming interface (API) is a set of subroutine definitions, communication protocols, and tools for building software. In general terms, it is a set of clearly defined methods of communication between various components.” -[Wikipedia]

“An application program interface (API) is a code that allows two software programs to communicate with each other.”-[TechTarget]

Not only these if you search on any website about API, they will explain it brilliantly,

But it is only understandable by those who have worked on API, but if you haven’t then it can be difficult to fully understand, although the explanation is perfect but not in easy words.

Goals:

The goal of this blog is simply to make you understand the meaning of API in more easy words.


So let’s begin with an easy example-

Suppose if you wanna book a ticket of a train, then it is possible to book tickets of the same train through various apps say IRCTC Official App, Paytm etc.

Now the main thing you need to understand is that how it is possible to book the same seat through two different Apps?

Yes, the answer lies in API.

What API is doing is just letting you use someone’s else code in your application.

Absolutely, PAYTM will be using API provided by IRCTC.

Take a look at this perfect video provided by Mulesoft:

I think you are now getting some idea of what API actually is?

Let’s look at another example-
Google is a huge website and it writes a tall pile of codes.
These codes are for various services like search, youtube, Gmail, etc. What if we want to use them?

You must have seen, many websites provide logging in through Google’s Login credentials in their apps. So in a second, you can log in on that third party app using your google account.

So what actually is happening behind this, third party-app is using Google’s API  for providing login. In easy words, they are using Google’s code for the login system and fitting in their app and using their features, without worrying about what they have written.

Types of API:

What is API?

Since this topic is very much wide…

Among all the types mentioned above , we will mainly focus on Web APIs aka Web-Services.

WEB-API:

 

Web API as the name suggests, is an API over the web which can be accessed using the HTTP protocol. It is a concept and not a technology. We can build Web API using different technologies such as Java, .NET etc. For example, Twitter’s REST APIs provide programmatic access to read and write data using which we can integrate twitter’s capabilities into our own application.

Types Of WEB-APIs:

Early on, one of the most popular enterprise formats for Web APIs was SOAP  But with the emergence of JavaScript Object Notation (JSON), we saw more reliance on HTTP and the growth of JSON APIs, while REST has grown in popularity and quickly become the de facto standard for general Web APIs today.

  • SOAP:

SOAP was designed back in 1998 by Dave Winer, Don Box, Bob Atkinson  and Mohsen Al-Ghosein for Microsoft Corporation. It was designed to offer a new protocol and messaging framework for the communication of applications over the Web. While SOAP can be used across different protocols, it requires a SOAP client to build and receive the different requests, and relies heavily on the Web Service Definition Language (WSDL) and XML:

<?xml
  version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-­‐envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-­‐
encoding">
<soap:Body
  xmlns:m="http://www.example.com/weather">
<m:GetWeather>
<m:pinCode>395007</m:pinCode>
</m:GetWeather>
</soap:Body>
</soap:Envelope>

 

Early on, SOAP did not have the strongest support in all languages, and it often became a tedious task for developers to integrate SOAP using the Web Service Definition Language.
However, SOAP calls can retain state, something that REST is not designed to do.

Before going to the next type, let’s understand a new term ,

RPC- “Remote Procedure Call (RPC) is a protocol that one program can use to request a service from a program located in another computer on a network without having to understand the network’s details.”

Apart from this definition, we can take it as a protocol working on the client-server model, without going much into detail

  • XML-RPC:

On the other hand, Remote Procedure Calls, or RPC APIs, are much  quicker and easier to implement than SOAP. XML-RPC was the basis for
SOAP, although many continued to use it in its most generic form, making simple calls over HTTP with the data formatted as XML.

However, like SOAP, RPC calls are tightly coupled and require the user to not only know the procedure name, but often the order of parameters as well. This means that developers would have to spend extensive amounts of time going through documentation to utilize an XML-RPC API, and keeping documentation in sync with the API was of utmost importance, as otherwise, a developer’s attempts at integrating it would be futile.

  • JSON-RPC

Introduced in 2002, the JavaScript Object Notation was developed by State Software, Inc.
The format was originally designed to take advantage of JavaScript’s ability to act as a messaging system between the client and the browser.

JSON was then developed to provide a simple, concise format that could
also, capture state and data types.
Yahoo started taking advantage of JSON in 2005, quickly followed by
Google in 2006. Since then JSON has enjoyed rapid adoption and wide language support, becoming the format of choice for most developers.
You can see the simplicity that JSON brought to data formatting as
compared to the SOAP/ XML format above:

{“pinCode":“395007”}

 

So, JSON presented a marked improvement over XML.

  • REST:

Now the most popular choice for API development, REST or RESTful APIs were designed to take advantage of existing protocols. While REST can be used over nearly any protocol, it typically takes advantage of HTTP when used for Web APIs. This means that developers do not need to install libraries or additional software in order to take advantage of a REST API. REST also provides an incredible layer of flexibility. Since data is not tied to methods and resources, REST has the ability to handle multiple types of calls, return different data formats.

Unlike SOAP, REST is not constrained to XML, but instead can return XML, JSON,  or any other format depending on what the client requests. And unlike RPC, users aren’t required to know procedure names or specific parameters in a specific order.

 

I think uptill now, the question “what the hack is API?”  is somewhat answered, but this  description is not enough , there are many things you still need to explore on your own. So keep exploring.

Thanks for reading..

Happy Learning! ..

TEAM CEV.

*Most Welcome to questions and doubts in comment section……….

**Resources:

 

#Objection accepted for copied images

CEV - Handout