Vertiport GPT Assistant

OpenAI and ChatGPT is dominating the LLM space for more than a year now, at least in media and public attention.

AI generated eVTOL design (Midjourney)

While ChatGPT 3.5 was already amazing, version 4.0 is a major step forward. GPT-4 comes with several notable features and capabilities that represent significant advancements over its predecessor. With supposedly 100 trillion parameters, it would surpass 3.5 500 times.

Released in March 2023, GPT-4 shows a better grasp of context, allowing for more relevant and coherent responses. It maintains coherence over longer passages, making it suitable for generating lengthy reports, stories, or detailed explanations. Trained on a more recent dataset, GPT-4 has access to newer information, making its responses more current. It improved in handling complex reasoning tasks, problem-solving, and analytical thinking and exhibits a lower propensity for generating incorrect or nonsensical responses, particularly in nuanced or complex subject areas.

Version 4 is solely available through subscription of currently at a cost of $20 per month.

Now we have the possibility to add knowledge to the model and make it accessible for private or public usage.

Let’s try a hands-on example, building a Vertiport Assistant to answer around eVTOLS and vertiports. It has already common knowledge about the topic.

Now let’s ask something that OpenAI has not scraped, like the FAA EB 105, the Engineering Brief that describes the design of vertiports. The document was released in March 2023 (GPT 4 covers information until April 2023) and is publically accessible at this link.

ChatGPT does not know about it, only provides some indication recognizing the meaning of FAA and EB.

Lets create a GPT and add the PDF file to it.

Note, I also added the EASA equivalent document, the PTS for Vertiports (March 2022) as well disabled web browsing to make sure we rely on uploaded knowledge only.

Now we receive an answer which is more or less a rephrased version of the document.

Asking for more specific informations results in deviations.

We are off by 5mm ?!

Conclusion: With the current version 4 we can integrate ChatGPT easily into other solutions, using its multimodal features and inject our own knowledge. Still, we have to be careful to rely on specific information and values.

Even more Airport Self-Service-Kiosk Designs in 2024

Another 6 months later (December 2023) and Midjourney released 6.0 as alpha for image creation, worth another visit to same and new design prompts. We are going more and more photorealistic without any additional prompt attributes. Some of the design are little practical I guess but certainly create a decorative element in the terminal.

Previous posts: How to design an Airport Self-Service-Kiosk (Jan 2023) and More Airport Self-Service-Kiosk Designs (Aug 2023)

Disclaimer: This is solely for educational purpose and does not reflect any actual products or design I am involved with (until today). No copyright infringement is intended.

Style of 1900s
Style of 1910s
Style of 1920s
Style of 1930s
Style of 1940s

Style of 1950s

Style of 1970s
Style of 1980s
Fantasy Dreamland Style
Mad Max Movie Style
Art Deco Style
Rococo Style
Gothic Style
Lord of the Rings Style
Kids Toy Style
Apple Design
Andy Warhol
Google Design
Neon Design
Joan Miro Design
Design by Pablo Picasso
Hieronymus Bosch Design
Salvador Dalí Design
Colani Design
Zaha Hadid Design

Conclusion: Runing Midjourney V6.0 creates very photorealistic images, that could easily been taken for a real photograph. It is mindboggling how much it advanced in one year. The challenge, create new unique designs that are not just copying the stykle of someone else. Though creativity contains inspiration and copyying.

More Airport Self-Service-Kiosk Designs

6 months later, the second round using the Midjourney 5.x release for image creation, worth another visit to same and new design prompts. Some of the design are little practical I guess but certainly create a decorative element in the terminal.

Disclaimer: This is solely for educational purpose and does not reflect any actual products or design I am involved with (until today). No copyright infringement is intended.

Technical Drawing in the 1970’s
1900’s
1910’s
1920’s
1930’s
1950’s
1970’s
1980’s
Art Deco
Romanesque Era
Renaissance
Caveman Style
Futurama Style
Simpsons Style
Rococo Style
Surrealism
Joan Miro
Pablo Picasso
Andy Warhol
Legoland
Playmobil

Fantasy Dreamland

Neon
Mad Max

How to design an Airport Self-Service-Kiosk

The Airport Kiosk is a common sight in all small and large airports, it offers a range of self-service features. Upon identification by reading identity cards, credit cards or boarding passes, we can use it to print tickets and boarding passes, print luggage tags, change seat, purchase in-flight-upgrades, spend frequent flyer points and more.
We might reach the stage where these kiosks are a thing of the past, but as long as we need (want) to print something and not 100% of all travellers manage their bookings and ancillary services with their smartphone, we will see them for a some while.

The design and look-and-feel of these kiosks are quite standard, why not create some new designs with our AI wizard assistants ?
I have to admit, I am quite addicted to Stable Diffusion and Midjourney. It is amazing what you can create (or what the AI creates) using nothing but words to describe something.

We are asking for different, fresh designs and want to create an airport experience that is tailored to all kinds of passenger profiles. Let’s give it a try !

We mix the term “self-service kiosk inside an airport terminal” with a variety of art or design styles and settings. Below you find 35 different interpretations. Note, for some art styles, the model didn’t manage to render an airport terminal environment but kept it’s origin. Not all styles are rendered accurately.

Disclaimer: This is solely for educational purpose and does not reflect any actual products or design I am involved with (until today). No copyright infringement is intended.

Technical drawing in the 1970’s

Standard Model

Resembles a mix of ATM and carpark machine.

Family Theme Kiosk

Pikachu

Disney Theme Park

Kids Toy #1 (I quite like this one)
Kids Toy #2
Pixar Style
Phantasy Dreamland Unicorn Style
Kiosk for Elves
Honourable Mention: Kiosk Lego Style

Different eras

Victorian Era
Rococo Era
Gothic Era
Renaissance Era
Romanesque Style
Art Deco Style
1900’s Style
1920’s Style
1930’s Style
1970’s Retro Style (why is it placed in a carpark lot ?)
Steam Punk Style
Mad Max Movie Style
Las Vegas Casino Style
Marvel Theme
Lord of the Rings

Various Designers and Artists

Karim Rashid (Designer)
Naoto Fukasawa (Designer)
Zaha Hadid (Designer)
Roy Lichtenstein (Artist)
Aleksandra Gaca (Designer)
Colani (Designer)

Other Products

Swarovski
Guess what brand …
Google Design
Siemens S62 Rotary Phone Design

Follow this Twitter account for more airport AI art.

AI-Created Website for a Groundhandling company

The online community is going wild with all kind of experiments and playtime with ChatGPT, GPT-3, Stable Diffusion, Dalle-E and Midjourney. Social media, Facebook, Twitter, Instagram and even the professional networking platform LinkedIn is full of posts (inclusive the ones I add here..).

Time to experiment further and let the AI create a (mockup) website and some marketing text for our fictitious Airport Groundhandling company called BestEverHandling Inc.

Website Landing Page Mockup

Prompt: create a website for an airport groundhandling services company called “BestEverHandling Inc.”, websites,ux,ui, online

Drafts created by Stable Diffusion

Thats not going to fly…..

Disruption by aircraft design

Drafts created by Midjourney

Frankenstein airframe design..

Final Mockup

Conclusion: We can create a visual mockup with no readable texts, maybe good enough for an initial design proposal or discussion. The images show disturbing corrupted or ‘Frankenstein’ creations of aircraft and equipment.

Marketing Text

We need to create some marketing text for the company. In order to provide some guidance to the language model I use the description from Wikipedia and Law Insider

Prompt for OpenGPT / GPT-3: 
In aviation, aircraft ground handling defines the servicing of an aircraft while it is on the ground and parked at a terminal gate of an airport.Ground handling services means the supply at an airport, on a fee or contract basis, of the following: airline representation, administration and supervision; passenger handling; baggage handling; ramp services; catering; air cargo and mail handling; fueling of an aircraft; aircraft servicing and cleaning; line maintenance; surface transport; flight operations, crew administration and flight planning. Ground handling services do not include self-handling; security; aircraft repair and maintenance; or management or operation of essential centralised airport infrastructure such as de-icing facilities, fuel distribution systems, baggage handling systems, and fixed intra-airport transport systems. 

Create a half page marketing style description of groundhandling services provided by the company "BestEverHandling Inc.".

Marketing text created by ChatGPT

Unlike the website visual mockup we get quickly a quite realistic text proposal.

BestEverHandling Inc. is your go-to provider for all your aircraft ground handling needs. Our team of experienced professionals offers a comprehensive range of services to ensure that your aircraft is serviced, loaded, and cleaned efficiently and effectively.
We offer a variety of ground handling services including:
-Airline representation, administration, and supervision
-Passenger handling, including check-in and boarding assistance-
-Baggage handling and management
-Ramp services, such as aircraft loading and unloading
-Catering services to ensure that your flight crew and passengers are well-fed
-Air cargo and mail handling
-Fueling of aircraft
-Aircraft servicing and cleaning, both inside and out
-Line maintenance services to ensure your aircraft is in top condition
-Surface transport and flight operations assistance
-Crew administration and flight planning

Our goal is to provide high-quality ground handling services to our clients and ensure that your aircraft is ready for take-off as soon as possible. Our team is available 24/7 to accommodate your needs, and we use state-of-the-art equipment to ensure that your cargo and baggage are handled safely and securely. We also use environmentally friendly cleaning products to keep your aircraft spotless.
Choose BestEverHandling Inc. for all your ground handling needs, and experience the difference in quality and reliability. With our expert team, you can be confident that your aircraft is in good hands.

Conclusion: It uses our input and creates text around it that could be used for different businesses, just by replacing the keywords.

Extra: AI-created Text Detection Tools

As quickly as the AI systems to create text have advanced, powerful tools to detect AI-generated text have kept pace. Lets test our text for fake creation.

General implication:

  • We will see more spam and scam created with this tool. Traditional spam still shows a lot of spelling or grammar mistakes, which helps to spot it.
  • In education and academia these detection tools are needed to allow verification of genuine content, similar problem like the good old copy-and-paste content from Wikipedia or other research papers (plagiarism).
  • The creation tools can be used to optimize text and whole websites for SEO purposes.
  • If future search tools going this direction, we wont have any reference check, aka where the merged information is originating from.

GPT-2 Output Detector Demo (free tool, but trained for GPT-2)

GPTZero (free)

Content at Scale (commercial, free test)

Airports as seen by Stable Diffusion

Stable Diffusion is a deep learning model that converts textual input into images, trained with a 5 billion image set (LAION-5B). Released by the collaboration between Stability AI, the Computer Vision & Learning Group at LMU Munich, and Runway AI, the source code and the model weights are publicly available.

I used the Hugging Face hosted model to create some artwork and images in various styles. Below you see 50 images created by the Stable Diffusion model, applied to the term airport and the art style, without further input.

Enjoy the tour !

New: More of this work ? Follow me on Twitter !

Airport Artwork

Renaissance Art

Expressionism

Ukiyo-E

Cubism

Futurism

Symbolism

Art Nouveau

Andy Warhol

Albrecht Dürer

Salvador Dali

Pop Art

Cartoon

Manga

Random Art Styles

Airport Photography

Airport

Groundhandling

Baggage Handling

Vertiport

Honorary Mention

Aircraft in steampunk style

Conclusion

  • The copyright of the creation is with the person creating the image, with the person starting the process, and not with the creator or the model, nor with the artists that created the original art styles or artwork.
  • Every image is unique, but you will see a ot of similar looking results depending on the terms used.
  • Some of the requested styles are not properly applied (from an artistic point of view), especially the exotic ones that quite likely have fewer source images only in the model.
  • A lot of the images have an high level of randomness and and unreal details. Though providing more details in the text, the images tend to become more realistic (see below sample).
  • Artists like Andy Warhol, Pablo Picasso, Salvador Dali spent a lifetime to create art pieces and shaped epochs of art, now is just the base or source for anyone to create something in 5 seconds, just with one click.
  • The technology is certainly amazing and becomes now accessible to everyone to play with it, but is it a creative process? We will see further hype and this kind of artwork popping up in public spaces (airport lounge) without an actual artist being involved.
  • We will see so much of it that it becomes boring and tiring.

“A group of astronauts loading baggage into an aircraft”

ChatGPT and Python in 5 minutes

The launch of OpenAI‘s ChatGPT in late November triggered quite a wave of excitement and attention by media, following the DALL E 2 hype earlier this year. Supposedly OpenAI acquired 1 million users in 5 days. The chatbot is built on top of the GPT3.5 language model and was created using the Reinforcement Learning from Human Feedback approach. The text results are often not distinguishable from a text written by a person and with ChatGPT we can have a conversation and not just a question-answer exchange.

Without jumping further into the world of NLP theory, we are going straight into exploring it, at a Hello World level, as a quick-start.

You have the choice of testing the chatbot by yourself on OpenAI’s website (account and login required) or, which is more interesting, let’s build some Python code to integrate the service into your own app. Please note, at the time of writing, the service is considered beta and free for research or prototyping. Certainly OpenAI will mature and monetize this service eventually and offer the usual pay-per-usage model.


Please note, the below sample code and API implementation is solely calling the GPT3 model

There are a few limitations we need to be aware about:

  • There is no realtime information. You cannot ask for the current weather or stock exchange information etc.
  • Like other language models the training data is huge but still limited.
  • OpenAI tried to improve the previous InstructGPT, but there is still wrong and bias information.
  • There is a variance in responses, a minor tweak to the question can trigger completely different answers.

In order to use the API we need an OpenAI account and an active API-key.

Let’s start up our favouritePython IDE and add then openai package.

To interact with the API is as simple as one method call with a couple of parameters to pass the API key, the prompt/question and the model engine.

completion = openai.Completion.create(
    engine=model_engine,
    prompt=prompt,
    max_tokens=1024,
    n=1,
    stop=None,
    temperature=0.5,
)

I highly recommend reviewing the documentation about the parameters, to choose the right model and the temperature parameter which influences the response accuracy and quality.

I could not resist asking an airport related question (the significance or meaning of the TOBT milestone in the airport ACD-M process). Lets make minor tweaks to the question, keeping the parameters identical and look at the variety in responses.

To provide a proper reference, lets look at the definition that we find in the IATA A-CDM recommendation booklet.

Now, lets challenge GPT3

Explain the significance of TOBT in the flight departure process to me. 

TOBT (Target Off-Block Time) is an important part of the flight departure process. It is the target time for when the aircraft is expected to push back from the gate and begin taxiing for takeoff. The TOBT is determined by the airline and is based on the estimated time for all pre-departure activities, including boarding, cargo and baggage loading, fueling, and any other necessary preparations. The TOBT is an important factor in ensuring that flights depart on time and arrive at their destination on schedule.

✔️ Comment: With the proper context, this is quite an accurate response, though there is no reference to the A-CDM process.


Explain the significance of A-CDM milestone TOBT to me.

A-CDM (Airport Collaborative Decision Making) is a process designed to improve the efficiency of airport operations. TOBT (Target Off-Block Time) is a milestone within the A-CDM process. It is the time that the aircraft is expected to leave the gate and begin its taxi to the runway. It is a key milestone because it sets the timeline for all other activities that must take place before the aircraft can take off. It is also used to coordinate the activities of all the different stakeholders involved, such as the airline, the airport, air traffic control, and ground handlers. By having a clear timeline, it ensures that all the necessary steps are completed in a timely manner and that the aircraft can depart on schedule.

✔️ Comment: The earlier answer with A-CDM context added.


Explain the significance of ACDM milestone TOBT to me.

ACDM milestone TOBT (Time of Beginning of Takeoff) is a critical milestone in the aircraft take-off process. It is the moment when the aircraft begins its take-off roll and is the point at which the aircraft is committed to taking off and can no longer abort the take-off. This milestone is important because it is a key indicator of the airplane’s readiness to take off and is used to determine when the aircraft is airborne and when the aircraft is legally considered to be in flight. It is also used to measure the time it takes for the aircraft to take off and the amount of runway used.

Comment: The missing hyphen sign in “ACDM” generates a wrong answer, plus some creativity, inventing a new milestone “Time of Beginning of Takeoff”.


What is airport TOBT ?

Airport TOBT (Turn Around Time) is the amount of time it takes for an aircraft to arrive at an airport, unload passengers, refuel, and depart again. It is typically measured in minutes, and is used to measure the efficiency of an airport's operations.

Comment: Here, we mix the turnaround definition into the response.


Explain the significance of TOBT to me.

TOBT (Time of Beginning of Task) is an important concept in project management. It is the point in time when a task begins and is used to measure the progress of the task. TOBT is used to create a timeline for the task and to track its progress. It is also used to help determine the costs associated with the task, as well as to identify any potential delays. TOBT is an important tool for project managers to effectively plan and manage their projects.

Comment: With no context provided, the response is pointing to a project management term.


Conclusion

  • The above test is by no means exhaustive or academic, rather a random test. But this way a person without any prior knowledge might interact with the chatbot to seek answers.
  • Minor changes lead to significant changes and even wrong answers. There is no transparency, no reference is provided, unlike Google, where you see the source of the information.
  • The above responses are not copied but assembled, note the differences in the explnation of the same term.

Airport AODB goes NoSQL (Part 2)

airport

Earlier I embarked on the journey to create an AODB based on a NoSQL datamodel, moving away from a relational model and discuss its benefits. As a quick refresher about What’s an AODB ? for the new reader, the elevator-pitch style version describing an AODB:

AODB – Aiport Operational Database
An AODB system is one of the core IT systems to support the airport ground operations, it integrates with various systems in the heterogeneous airport IT landscape by processing data from airline seasonal flights schedules, flight plan and slot management, ground movement from Radar, air movement from ATC, and other sources. It serves as CDM (Collaborative Decision Making) platform for the various parties and stakeholders forming the airport community, from airport operators, airlines, groundhandling agents, authorities to ATC (Air Traffic Control) and others.
It handles seasonal and operational flights by providing planning, real-time and historical data, supports resource management for facilities, equipment and human resource and feeding information to public via FIDS and other external links. The below diagram shows an exemplary common orchestration of systems where the AODB is embedded at the core.

airport_systems_20181030

Now lets have a look at the typical data layout and relation of flight data entities and attributes. These are the common business entities and a relational model is the traditional approach to design it. We need to apply a rather high level of normalization to avoid redundant data, but the relations (typical 1:N) across the model have an impact on the performance of the DB. This can be counterbalanced by tuning, indexing and more powerful hardware underneath. Building SQL statements with joins across several tables becomes challenging (hard to create) and might cause inefficient reads of tables (full table scan). In comparison with a NoSQL design we have a document approach, one document (like a index card in the analog world) would contain all relevant data (ignoring the redundancy problem for now).
At the end of this exercise we have to ask the question: Is NoSQL the right tool for an AODB ? (We will revisit this question later on)

objects_20181030b

I like to elaborate the redundancy problem on one particular case:
A flight is operated with a specific aircraft (registration, tail number) on a certain date. The related information (AC Type, seats, owner, lease, etc) we retrieve from the relational table (containing all aircrafts in the system,) quite the standard scenario. The problem starts when we keep operational data long term (years) for auditing/research/statistical purpose. It is quite common registrations get transferred due to sale or scrapping of aircraft (find a sample here). Using the relational model with an aircraft registration table that only carries current registrations we would end up looking at the wrong information for a historical flight that operated on the previous aircraft with the same registration. A solution would be introducing the concept of validity for certain entities ,which again adds to the complexity.

The main problem is not solved, we should not replicate or mimic a relational model with NoSQL. Keeping the data redundant will increase the data volume but we would have one document with all relevant information. One usecase which is appealing for the document approach is creating a final snapshot of the flight in an archive like repository. The design question we have to answer, what data or details of the operations lifecyle (schedule, planning, operation, post-operation) we want to keep in the flight “document” ?

As an academic exercise, lets get started and create the most basic (primitive) version of a flight document in JSON format and look at all its weakness to start to evolve to improved versions of it.

{
  "flight": "AA123D",
  "org": "AKA",
  "des": "FRA",
  "service": "J",
  "actype": "A350",
  "position": "Z19",
  "gate": "A5",
  "baggagebelt": "09",
  "scheddep": "2017-11-23T19:35:00.000Z",
  "schedarr": "2016-11-24T13:15:00.000Z",
  "estimatearr": "2016-11-24T13:55:00.000Z",
  "estimatedep": "2016-11-23T19:39:00.000Z",
  "onblock": "2016-11-23T13:35:00.000Z",
  "offblock": "2016-11-23T19:31:00.000Z",
  "landed": "2016-11-23T13:27:00.000Z",
  "airborne": "2016-11-23T19:39:00.000Z",
  "pax": "128",
  "via": [
    "ABR",
    "ACL"
  ],
  "codeshare": [
    "LH123",
    "TG123",
    "AF123"
  ]
}

What is good about this entry level model ? Not too much other than highlighting the benefit to have all info in one document.

Lets look at the problems, at least the highlights. There is quite a number of attributes missing (eg. registration) but here the main flaws:

  • There is no clear concept of the flight as entity. Is it a segment or a complete journey ?
  • No naming convention, more or less random abbreviation for eg. timings.
  • No proper key identifier.No separation of airline code, flight number and suffix, missing schedule departure date (as key).
  • Resource should be an array of objects. Multiple resources with different timings might be in use.
    Same applies to any pax or cargo/load data.
  • Representing VIA and CS information like this might be good enough for a FIDS system but for a mature model we need to break down the whole entity into segments.
  • No links which provide dependencies to other segments, codeshares, arrival or departures.
  • Milestones (timings) should be an array too.
  • No audit information. (Might not in the scope of our model though.)
  • No unique (technical) identifier beyond flight keys.

We will elaborate and finetune in upcoming posts. Stay tuned.

Disclaimer: This discussion, datamodel and application is for study purpose solely. It does not reflect or replicate any existing commercial product.

Image: Creative Commons, DeGolyer Library, Southern Methodist University on The Commons, “DC-3 Aircraft at Houston Municipal Airport, Eastern Airlines”

METAR and TAF Webservice

ozedf

I am regularly exploring the Web Service space in the aviation domain looking for new datasets and feeds. I just stumbled upon CheckWX.com collecting weather messages from various sources and redistribute them. Thanks to Henry who is operating the page (it is not run by a company) we have access to big pool of weather messages via an API. The WS use is free, as long you wont hit the service with more than 2000 calls a day.

METAR (Meteorological Terminal Aviation Routine Weather Report) is a weather forecast in a standard message format, usually used by pilots for the pre-flight briefing. The standard defined by ICAO. The data is collected by weather observation stations.
TAF (Terminal aerodrome forecast), similar to METAR focus on aerodromes and provides a forecast for the next ~24 hours, usually every 6 hours.

You find more information in the ICAO reference “Manual of Aeronautical Meteorological Practice” or in the Airforce “Aircrew Quick Reference to the METAR and TAF Codes”.

Lets build a 5min Android app, similar to the BA Webservice client in a previous post. Thanks to the OkHttp library we get data nicely JSON formatted with a few lines of code. We just need to pass the airportcode (ICAO) to get back the current METAR info (plus some extra info about the airport).

private void callWXweatherService(String airportCode) {

	OkHttpClient httpClient = new OkHttpClient();
	String callURL = "https://api.checkwx.com/metar/" + airportCode + "/decoded";

	Request request = new Request.Builder().url(callURL)
			.addHeader("Content-Type", "application/json")
			.addHeader("X-API-KEY", "{your own API key}")
			.build();

	httpClient.newCall(request).enqueue(new Callback() {
		@Override
		public void onFailure(Call call, IOException e) {
			System.out.println("WS Call failed (1):" + e.getMessage());
		}

		@Override
		public void onResponse(Call call, Response response) {
			ResponseBody responseBody = response.body();
			if (!response.isSuccessful()) {
				final String errRep = "WS Call failed (2):" + response.toString();
			} else {
				try {
					System.out.println("Response " + response.toString());
					String str = new String(responseBody.bytes());
					final JSONObject svcresponse = new JSONObject(str);
					int spacesToIndentEachLevel = 2;
					final String prettyPrintString = svcresponse.toString(spacesToIndentEachLevel);

				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
	});
}

The API documentation: api.checkwx.com

screenshotcheckwx

If I have time I will create a better readable gui and integrate with Google Maps.

Disclaimer: This discussion, datamodel and sourcecode or application is for study purpose solely. It does not reflect or replicate any existing commercial product. It is also not fit for or meant for production.

Please note, weather data from CheckWX is not a substitute for an official weather briefing.

Blockchain – Big Topic broken down to pieces Part 2 (Bag Custody Sample)

bccloud3

I will continue the exploration of the basic components of the blockchain technology started in the previous post, where I implemented a basic java class to visualize hashing and the linking of blocks (chain). To provide a sample for the aviation industry walking along the use-case of tracking the baggage custody changes during a flight journey .

3. Validation

A blockchain need to be validated otherwise we would not know if data was changed or corrupted. We have to iterate through the sequence of blocks, for this we create an array of bag transactions to allow easy iteration and compare the stored hash of each block with the recalculated hash. If the values match the blockchain is valid, if not it is corrupted (and all subsequent blocks). Ideally this would be event-driven, any change to the blockchain triggers the revalidation. In a real-world implementation changes through the endpoints would not be possible, something we will look at later when working with Corda or Ethereum.

		String currentBagBlockHash = "0";

		String myBagTag = randomBagTagID();
		String myPNR = randomPNR();

		ArrayList allBagTransactions = new ArrayList();
		BagTransaction tempBagTransaction = null;

		// Print Bag Tag (Genesis Block)
		tempBagTransaction = new BagTransaction(myBagTag, myPNR, Entity.NIL.name(), Entity.PAX.name(), 0, "0");
		currentBagBlockHash = tempBagTransaction.getHash();
		allBagTransactions.add(tempBagTransaction);

...

public void checkBlockchainIntegrity(ArrayList allBagTransactions) {
	// Check Blockchain. Compare recalculated hash with hash attribute stored

	for (BagTransaction b : allBagTransactions){
		System.out.print("Block " + b.getBlockID() + " Stored Hash: " + b.getHash() + " -- Calculated Hash:" + b.createHash());
		if (b.getHash().equals(b.createHash()))
			System.out.println(" -- OK");
		else
			System.out.println(" -- FAIL. Blockchain broken.");
	}
	System.out.println(" -- ");
}
	}

For better reading we convert each block into a JSON object.

{
  "timeStamp": "2018-08-26T09:18:09.227Z",
  "blockID": 0,
  "blockHash": "ce41abbf21a162152e30fc511eaf594db43c84948691d12ef78fad6f31fa6043",
  "previousBlockHash": "0",
  "bagTag": "5347241966",
  "pnr": "EONT9T",
  "custodyTransfer": [
    {"transferFrom": "NIL"},
    {"transferTo": "PAX"}
  ]
}
{
  "timeStamp": "2018-08-26T09:18:09.287Z",
  "blockID": 1,
  "blockHash": "6b6073122ef996acc1e3c3e74c3963b5903112800781b4ba88e96baf0a8e2e04",
  "previousBlockHash": "ce41abbf21a162152e30fc511eaf594db43c84948691d12ef78fad6f31fa6043",
  "bagTag": "5347241966",
  "pnr": "EONT9T",
  "custodyTransfer": [
    {"transferFrom": "PAX"},
    {"transferTo": "AIRP"}
  ]
}

Running the validation for a clean and corrupted blockchain

Block 0 Stored Hash: ce41abbf21a162152e30fc511eaf594db43c84948691d12ef78fad6f31fa6043 -- Calculated Hash:ce41abbf21a162152e30fc511eaf594db43c84948691d12ef78fad6f31fa6043 -- OK
Block 1 Stored Hash: 6b6073122ef996acc1e3c3e74c3963b5903112800781b4ba88e96baf0a8e2e04 -- Calculated Hash:6b6073122ef996acc1e3c3e74c3963b5903112800781b4ba88e96baf0a8e2e04 -- OK
Block 2 Stored Hash: a33bbb5ebdec589e9f1b7c7952d6fef3fae2235b5a0600b8755b07040bba8227 -- Calculated Hash:a33bbb5ebdec589e9f1b7c7952d6fef3fae2235b5a0600b8755b07040bba8227 -- OK
Block 2 Stored Hash: 464319fed3a2c49df9a1fbeedae3f3e7c6692db0f6ab97a4c983f9fdf4269e6d -- Calculated Hash:464319fed3a2c49df9a1fbeedae3f3e7c6692db0f6ab97a4c983f9fdf4269e6d -- OK
-- Now corrupt Block 1 by changing the data
Block 0 Stored Hash: ce41abbf21a162152e30fc511eaf594db43c84948691d12ef78fad6f31fa6043 -- Calculated Hash:ce41abbf21a162152e30fc511eaf594db43c84948691d12ef78fad6f31fa6043 -- OK
Block 1 Stored Hash: 6b6073122ef996acc1e3c3e74c3963b5903112800781b4ba88e96baf0a8e2e04 -- Calculated Hash:09fd4223571f079258bd69d935f99cb552cd3ac0854410b81a2313d215929ebd -- FAIL. Blockchain broken.

 

4. Mining Blocks

Now we get to the first more complex concepts of the blockchain, the mining process. We are still operating at a very basic level though with a single node, but we can introduce the mining operation. Without going into too much detail, mining blocks is the step to close/hash a block and creating a new one as part of the consensus process. The incentive to the miner community is a transaction fee given to that miner that solves a hard cryptographic problem first. The more computing power you invested in, the higher chance you have as miner to solve the problem and get the fee. Based on scarcity this consensus approach is called Proof-of-Work (recommended reading). Unfortunately this lead to the current hardware race consuming vast amount of energy for literally no purpose (you let CPU/GPU’s guess numbers basically). This is seen as limitation, together with the long transaction times, and some blockchain start to move to other concepts, such as Proof-of-Stake.

Breaking down the Proof-of-Work to a simple algorithm, we build a hash function that need to create a certain pattern before being accepted. The hash of (data current block + hash previous block + a nonce value) need to have a number of leading “0” in front. The number of “0” is the difficulty and the nonce is an integer value that is changed/increased until the hash matches the required pattern.

public String mineHash(int difficulty) {
	String returnHash = "";
	String tempHash = "";

	String target = new String(new char[difficulty]).replace('\0', '0');
	tempHash = createHash();

	while (!tempHash.substring(0, difficulty).equals(target)) {
		nonce++;
		tempHash = createHash();
	}

	return tempHash;
}

With a growing difficulty (more leading “0”) it takes obviously longer to crack the challenge and with more CPU power you can run through the guessing cycle faster. Some samples below with increasing difficulty running on an ordinary notebook i7 CPU (java executing on a single core/thread in this case).

Difficulty: 1
Attempts: 11
Milliseconds: 10

Difficulty: 2
Attempts: 393
Milliseconds: 30

Difficulty: 3
Attempts: 1.794
Milliseconds: 40

Difficulty: 4
Attempts: 115.756
Milliseconds: 230

Difficulty: 5
Attempts: 3.366.041
Milliseconds: 3.210

Difficulty: 6
Attempts: 5.322.279
Milliseconds: 4.530

Difficulty: 7
Attempts: 76.339.743
Milliseconds: 60.850

Block
{
  "timeStamp": "2018-08-26T10:38:36.734Z",
  "blockID": 0,
  "blockHash": "0000000158d606c953a5df346d459aad949e9dbb4abe74f30ecf225c23112b14",
  "previousBlockHash": "0",
  "bagTag": "7821666095",
  "pnr": "ZHY4RT",
  "custodyTransfer": [
    {"transferFrom": "NIL"},
    {"transferTo": "PAX"}
  ]
}

Have a look at the below website for the current real life difficulty for bitcoin (hashing algorithm not implemented in the simple way we did it here for illustration purpose). Looking at the current difficulty (6,727,225,469,722) you can guess what kind of hardware setup you need to be fast. I gave up beyond difficulty 7 with the algorithm above.

Bitcoin Difficulty

Stay tuned for more blockchain.

Disclaimer: This discussion, datamodel and sourcecode or application is for study purpose solely. It does not reflect or replicate any existing commercial product.

Sourcecode at github