abci

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 29, 2022 License: AGPL-3.0 Imports: 42 Imported by: 0

README

Application BlockChain Interface (ABCI)

Introduction

The purpose of this package is to interface with the specific Tendermint blockchain ("the Calendar") which serves as the event bus, storage layer, and consensus mechanism for the Chainpoint Network.

The entrypoint, called by the main abci-service.go file in the parent directory, is abci.go. From here the application coordinates the corresponding functions from the following files:

  • tasks.go: Periodic tasks
  • anchor.go: Calendar anchoring every tendermint block and BTC anchoring every 60 blocks
  • api.go: Http API for submitting hashes and retrieving proofs
  • identity.go: Methods for submitting, saving, and verifying core identities
  • leader.go: Elects a lead core based on a shared random seed

Chainpoint Protocol

All Chainpoint transactions follow this json format:

{
"type":<string>,
"data":<string>,
"version:<int64>,
"time":<unix;int64>,
"CoreID":<string>,
"Meta":<string>,
"Sig":<ECDSA signature of all fields above>
}

Each new Chainpoint Core shall open a lightning channel to all other Cores, then issue a JWK tendermint transaction that includes their ECDSA public key and lightning public key.

Once a minute, all Cores shall submit the merkle root of all hashes collected over the past minute as a CAL tendermint transaction.

Once every hour, a Core is elected to aggregated all CAL merkle roots over the past hour into a new merkle tree. The new merkle root is placed in a OP_RETURN transaction on the bitcoin blockchain. Upon 1 confirmation, the anchoring Core issues a BTC-A transaction with the associated bitcoin tx body, block height, and ID.

After 6 confirmations of the previous bitcoin transaction, a validator Core will be elected to confirm the transaction. If the transaction is confirmed, this Core issues a BTC-C transaction to the rest of the chain.

Upon receiving a BTC-C transaction, all Cores generate their final btc timestamp proofs for the hour covered by that bitcoin transaction.

Proof Generation

The Chainpoint Network generates calender proofs every minute and bitcoin proofs roughly every 90 minutes. This is essentially a multi-level Merkle Tree that builds until the top root reaches bitcoin.

The initial Merkle Tree construction creates Calendar roots from submitted hashes:

  1. A hash is submitted to the Merkle Tree aggregator via the API.
  2. An agg state is created, representing the initial hashes being merkelized.
  3. When aggregation states are in the process of being accumulated into a calendar anchor, a cal state is created.
  4. The cal states are queried and added to each individual aggregation state to produce a compelete cryptographic chain demonstrating inclusion of each hash in the Chainpoint Calendar. The proofs are then cached in the proof table in json format for download.

A similar process occurs for turning Calendar roots into BTC proofs:

  1. A group of Calendar roots is aggregated into a Merkle tree. The root is submitted to Bitcoin.
  2. The submitted Calendar roots are turned into Anchor Btc Agg State objects and stored.
  3. Information about the BTC transaction is stored in the btctx state.
  4. After 6 confirmations, information about the BTC block is used to reconstruct the Merkle Tree in the Bitcoin block header. This information is stored in btchead state table and is used to demonstrate that our btc transaction is included in the Bitcoin blockchain.
  5. The Merkle Trees stored in (2) are added to the Bitcoin block Merkle Tree to show how each calendar root relates to the Bitcoin block header. The proof object for every hash that has a calendar root included in this btc batch is then updated with this new information, available for download.

Documentation

Index

Constants

View Source
const STATIC_FEE_AMT = 0 // 60k amounts to 240 sat/vbyte
View Source
const SUCCESSFUL_ANCHOR_CRITERIA = 100
View Source
const (
	ValidatorSetChangePrefix string = "val:"
)

constant prefix for a validator transaction

Variables

View Source
var (
	ProtocolVersion version.Protocol = 0x1
	GossipTxs                        = []string{"NIST"}
)

variables for protocol version and main db state key

Functions

func MakeValSetChangeTx

func MakeValSetChangeTx(pubkey types.PubKey, power int64) []byte

MakeValSetChangeTx : TODO: describe this

func ValidateValidatorTx

func ValidateValidatorTx(val string) (err error, id string, pubkey []byte, power int64, blockHeight int64)

Types

type AnchorApplication

type AnchorApplication struct {
	types2.BaseApplication
	// validator set
	ValUpdates []types2.ValidatorUpdate

	PendingValidator     string
	PendingChangeStake   int64
	NodeRewardSignatures []string
	CoreRewardSignatures []string
	Db                   dbm.DB
	Anchor               anchor.AnchorEngine

	ChainpointDb database.ChainpointDatabase
	Cache        *level.KVStore
	LnClient     *lightning.LightningClient

	ID            string
	JWK           types.Jwk
	Analytics     *analytics2.UniversalAnalytics
	ULIDGenerator *threadsafe_ulid.ThreadSafeUlid
	// contains filtered or unexported fields
}

AnchorApplication : AnchorState and config variables for the abci app

func NewAnchorApplication

func NewAnchorApplication(config types.AnchorConfig) *AnchorApplication

NewAnchorApplication is ABCI app constructor

func (*AnchorApplication) AnchorCalendar

func (app *AnchorApplication) AnchorCalendar(height int64) (int, error)

AnchorCalendar : Aggregate submitted hashes into a calendar transaction

func (*AnchorApplication) BeaconMonitor

func (app *AnchorApplication) BeaconMonitor()

BeaconMonitor : elects a leader to poll DRAND. Called every minute by ABCI.commit

func (*AnchorApplication) BeginBlock

BeginBlock : Handler that runs at the beginning of every block

func (*AnchorApplication) CalDataHandler

func (app *AnchorApplication) CalDataHandler(w http.ResponseWriter, r *http.Request)

func (*AnchorApplication) CalHandler

func (app *AnchorApplication) CalHandler(w http.ResponseWriter, r *http.Request)

func (*AnchorApplication) CheckTx

CheckTx : Pre-gossip validation

func (*AnchorApplication) CheckVoteChangeStake

func (app *AnchorApplication) CheckVoteChangeStake()

func (*AnchorApplication) CheckVoteValidator

func (app *AnchorApplication) CheckVoteValidator()

func (*AnchorApplication) Commit

func (app *AnchorApplication) Commit() types2.ResponseCommit

Commit is called at the end of every block to finalize and save chain state

func (*AnchorApplication) DeliverTx

DeliverTx : tx is url encoded json

func (*AnchorApplication) EndBlock

EndBlock : Handler that runs at the end of every block, validators can be updated here

func (*AnchorApplication) FeeMonitor

func (app *AnchorApplication) FeeMonitor()

FeeMonitor : elects a leader to poll and gossip Fee. Called every n minutes by ABCI.commit

func (*AnchorApplication) GatewaysHandler

func (app *AnchorApplication) GatewaysHandler(w http.ResponseWriter, r *http.Request)

func (*AnchorApplication) GenerateCalBatch

func (app *AnchorApplication) GenerateCalBatch(aggStates []types.AggState, calStates []types.CalStateObject) error

func (*AnchorApplication) HashHandler

func (app *AnchorApplication) HashHandler(w http.ResponseWriter, r *http.Request)

func (*AnchorApplication) HomeHandler

func (app *AnchorApplication) HomeHandler(w http.ResponseWriter, r *http.Request)

func (*AnchorApplication) Info

func (app *AnchorApplication) Info(req types2.RequestInfo) (resInfo types2.ResponseInfo)

Info : Return the state of the current application in JSON

func (*AnchorApplication) InitChain

InitChain : Save the validators in the merkle tree

func (*AnchorApplication) LoadIdentity

func (app *AnchorApplication) LoadIdentity() error

LoadIdentity : load public keys derived from JWTs from redis

func (*AnchorApplication) LogError

func (app *AnchorApplication) LogError(err error) error

func (*AnchorApplication) PeerHandler

func (app *AnchorApplication) PeerHandler(w http.ResponseWriter, r *http.Request)

func (*AnchorApplication) ProofHandler

func (app *AnchorApplication) ProofHandler(w http.ResponseWriter, r *http.Request)

func (*AnchorApplication) Query

func (app *AnchorApplication) Query(reqQuery types2.RequestQuery) (resQuery types2.ResponseQuery)

Query : Custom ABCI query method.

func (*AnchorApplication) SaveIdentity

func (app *AnchorApplication) SaveIdentity(tx types.Tx) error

SaveIdentity : save the JWK value retrieved, and list ourselves as staked if we sent it

func (*AnchorApplication) SendIdentity

func (app *AnchorApplication) SendIdentity() error

func (*AnchorApplication) SetIdentity

func (app *AnchorApplication) SetIdentity(tx types.Tx) (types.Jwk, error)

func (*AnchorApplication) SetOption

SetOption : Method for runtime data transfer between other apps and ABCI

func (*AnchorApplication) SetStake

func (app *AnchorApplication) SetStake()

func (*AnchorApplication) StakeIdentity

func (app *AnchorApplication) StakeIdentity()

StakeIdentity : updates active ECDSA public keys from all accessible peers Also ensures api is online

func (*AnchorApplication) StartAnchoring

func (app *AnchorApplication) StartAnchoring()

StartAnchoring: StartAnchoring calendar and btc blockchains

func (*AnchorApplication) StatusHandler

func (app *AnchorApplication) StatusHandler(w http.ResponseWriter, r *http.Request)

func (*AnchorApplication) SyncMonitor

func (app *AnchorApplication) SyncMonitor()

SyncMonitor : turns off anchoring if we're not synced. Not cron scheduled since we need it to start immediately.

func (*AnchorApplication) VerifyIdentity

func (app *AnchorApplication) VerifyIdentity(tx types.Tx) bool

VerifyIdentity : Verify that a channel exists only if we're a validator and the chain is synced

type Hash

type Hash struct {
	Hash string `json:"hash`
}

type HashResponse

type HashResponse struct {
	Hash            string          `json:"hash"`
	ProofId         string          `json:"proof_id"`
	HashReceived    string          `json:"hash_received"`
	ProcessingHints ProcessingHints `json:"processing_hints"`
}

type ProcessingHints

type ProcessingHints struct {
	CalHint string `json:"cal"`
	BtcHint string `json:"btc"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL