question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

feat(core-api): hasTransactionFinality(): boolean on connector API

See original GitHub issue

Is your feature request related to a problem? Please describe.

Need a way to ask the connector at runtime whether its ledger has transaction finality guaranteed or not.

Describe the solution you’d like

Depends on #355

A method on the connector that returns a boolean, something like:

For ledgers that only support one consensus algorithm (public permissionless ledgers mostly I guess?)

public hasTransactionFinality(): Promise<boolean> {
    return false;
}

In cases where the ledger has configurable consensus the function’s return value would depend on which one is configured for the current ledger instance.

public async hasTransactionFinality(): Promise<boolean> {
    const algorithmsWithTxFinality = ["IBFT2", "RAFT", "Other_Algo"];
    const algorithmsWithOutTxFinality = ["Proof_of_Work", "Some_Other_Algo"];
    const currentAlgo = await this.getConsensusAlgorithm();
    const unrecognizedAlgorithm = !algorithmsWithTxFinality.includes(currentAlgo) &&  !algorithmsWithOutTxFinality.includes(currentAlgo);
    if (unrecognizedAlgorithm) { // fail fast when algorithm is unrecognized
        throw new Error(`Unrecognized consensus algorithm: ${currentAlgo}`);
    } else {
        return algorithmsWithTxFinality.includes(currentAlgo);
    }
}

To avoid the problem of a ledger introducing a new consensus algorithm that does support TX finality and then us returning incorrect results based on that, we must check the currentAlgo for presence in both lists and throw if it isn’t present in either one of them. This guarantees that we fail fast instead of non-deterministic behavior.

Describe alternatives you’ve considered

Another way of going about this would be to have the consensus algorithms defined in the consortium definition which would provide us with the means to have the consensus algorithm locked down. Not sure if we should do this because the problem is regarding enforcement: Big mistakes can still happen if a consortium member accidentally changes the consensus algorithm of their own ledger without seeking an update in the consensus definition first.

cc: @sfuji822 @takeutak @jonathan-m-hamilton

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
petermetzcommented, Apr 17, 2021

@jscode017 Thanks for teaching me about "x-enum-varnames" I was looking for something like that in the OpenAPI specs just the other day to be able to control the enum variable names!

Back on-topic: Yeah you might not need to declare an array at all, because of the way you structured your enum you could just check later in code if an algorithm name is part of that enum, the same way they are advising at Check if value exists in enum in TypeScript

That array thing would only be needed if you had one enum containing both the algos with and without tx finality IMO (that was my initial idea, but I like yours better). The way you did it is probably better because then the information is encoded in the enum at design time (when you are typingthe openapi.json file).

1reaction
petermetzcommented, Apr 8, 2021

@jscode017 Sure thing, that works and thank you for taking this up!

Read more comments on GitHub >

github_iconTop Results From Across the Web

feat(core-api): getConsensusAlgorithm() on connector API · Issue ...
Please describe. We need a way for the ledger connector plugins to be queried at runtime for the consensus algorithm they use. This...
Read more >
Core API
Core API is a format-independent Document Object Model for representing Web APIs. It can be used to represent either Schema or Hypermedia responses, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found