angine

package module
v0.0.0-...-d3be70c Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2017 License: Apache-2.0 Imports: 26 Imported by: 0

README

What is angine?

Angine is a completely self-contained blockchain consensus engine. At the core, we use Tendermint BFT. It is an implementation of a Byzantine Fault Tolerant PoS consensus algorithm. So thank you Tendermint team. We just wrap those many things that tendermint already offered together under a concept, "Angine".

Structure of Angine

├── blockchain
│   ├── pool.go
│   ├── pool_test.go
│   ├── reactor.go
│   └── store.go
├── config
│   ├── config.go
│   └── templates.go
├── consensus
│   ├── byzantine_test.go
│   ├── common.go
│   ├── common_test.go
│   ├── height_vote_set.go
│   ├── height_vote_set_test.go
│   ├── mempool_test.go
│   ├── reactor.go
│   ├── reactor_test.go
│   ├── README.md
│   ├── replay.go
│   ├── replay_test.go
│   ├── state.go
│   ├── state_test.go
│   ├── test_data
│   │   ├── build.sh
│   │   ├── empty_block.cswal
│   │   ├── README.md
│   │   ├── small_block1.cswal
│   │   └── small_block2.cswal
│   ├── ticker.go
│   ├── version.go
│   └── wal.go
├── angine.go
├── log.go
├── mempool
│   ├── mempool.go
│   ├── mempool_test.go
│   └── reactor.go
├── plugin
│   ├── init.go
│   └── specialop.go
├── README.org
├── refuse_list
│   ├── refuse_list.go
│   └── refuse_list_test.go
├── specialop.go
├── state
│   ├── errors.go
│   ├── execution.go
│   ├── execution_test.go
│   ├── plugin.go
│   ├── state.go
│   └── state_test.go
└── types
    ├── application.go
    ├── block.go
    ├── block_meta.go
    ├── canonical_json.go
    ├── common.go
    ├── events.go
    ├── genesis.go
    ├── hooks.go
    ├── keys.go
    ├── mempool.go
    ├── part_set.go
    ├── part_set_test.go
    ├── priv_validator.go
    ├── proposal.go
    ├── proposal_test.go
    ├── resultcode.go
    ├── result.go
    ├── rpc.go
    ├── signable.go
    ├── specialOP.go
    ├── tx.go
    ├── validator.go
    ├── validator_set.go
    ├── validator_set_test.go
    ├── vote.go
    ├── vote_set.go
    ├── vote_set_test.go
    └── vote_test.go

This is directory structure of Angine, you can see that we have packed every module under its own directory. This give you a clear view of the parts making up an Angine.

  1. state/ is the running state of the Angine, which is driven by blockchain/, mempool/ and consensus/

  2. blockchain/ takes charge of syncing blocks, loading blocks, persisting blocks and anything that physically related to "block"

  3. mempool/ takes charge of buffering effective transactions and reaching an agreement about the order of transactions

  4. consensus/ takes charge of gossipping between peers, consensus algorithm related data stream

What we have fulfilled

  1. CA based on asymmetric cyrpto

  2. Dynamically changing ValidatorSet of ConsensusState

  3. Two kinds of transactions, normal and special, are totally isolated. Special tx will only be processed by plugins.

  4. Angine plugins

How to use

Initialize Angine

This is how you initialize an angine.

angine.Initialize(&angine.AngineTunes{Conf: conf})

The "angine.Initialize" will handle the generation of default configs, genesis file and private key. You must only do this once for a particular chain, otherwise, your id might be different.

Construct an AngineTunes.
type AngineTunes struct {
    Runtime string
    Conf    *cfg.MapConfig
}

This struct contains 2 fields and you only have to fill one:

  1. Runtime is a path that contains all the auto-generated files. So provided this will just generate everything under this path with random chainID and private/pub key pair.

  2. Conf contains anyconfig that you want to override the defaults. Say, you wanna use some cli args to override the default configs, this is the thing you should look into.

    After, you probably need to edit those files mannually to get exactly what you want. Everything in the files are straigt forward.

New an Agnine instance and start it

First, you need to import angine into your project :-) then,

import "github.com/annchain/angine"

...

mainAngine := angine.NewAngine(&angine.AngineTunes{Conf: conf})

...

mainAngine.Start()

That is all.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckSpecialOPVoteSig

func CheckSpecialOPVoteSig(cmd *types.SpecialOPCmd, pk crypto.PubKey, sigData []byte) error

func Initialize

func Initialize(tune *AngineTunes)

func InitializeLog

func InitializeLog(env, logpath string) *zap.Logger

func ProtocolAndAddress

func ProtocolAndAddress(listenAddr string) (string, string)

Defaults to tcp

Types

type Angine

type Angine struct {
	// contains filtered or unexported fields
}

Angine is a high level abstraction of all the state, consensus, mempool blah blah...

func NewAngine

func NewAngine(tune *AngineTunes) *Angine

NewAngine makes and returns a new angine, which can be used directly after being imported

func (*Angine) BroadcastTx

func (e *Angine) BroadcastTx(tx []byte) error

func (*Angine) BroadcastTxCommit

func (e *Angine) BroadcastTxCommit(tx []byte) error

func (*Angine) CheckSpecialOp

func (e *Angine) CheckSpecialOp(cmd *types.SpecialOPCmd) ([]byte, error)

func (*Angine) CollectSpecialVotes

func (e *Angine) CollectSpecialVotes(cmd *types.SpecialOPCmd, tx []byte) error

CollectSpecialVotes returns nil means the vote passed

func (*Angine) ConnectApp

func (e *Angine) ConnectApp(app types.Application)

func (*Angine) DialSeeds

func (e *Angine) DialSeeds(seeds []string)

func (*Angine) FlushMempool

func (e *Angine) FlushMempool()

func (*Angine) Genesis

func (e *Angine) Genesis() *types.GenesisDoc

func (*Angine) GetBlacklist

func (e *Angine) GetBlacklist() []string

func (*Angine) GetBlock

func (e *Angine) GetBlock(height int) (*types.Block, *types.BlockMeta)

func (*Angine) GetConsensusStateInfo

func (e *Angine) GetConsensusStateInfo() (string, []string)

func (*Angine) GetNodeInfo

func (e *Angine) GetNodeInfo() *p2p.NodeInfo

func (*Angine) GetNumPeers

func (e *Angine) GetNumPeers() int

func (*Angine) GetNumUnconfirmedTxs

func (e *Angine) GetNumUnconfirmedTxs() int

func (*Angine) GetP2PNetInfo

func (e *Angine) GetP2PNetInfo() (bool, []string, []*types.Peer)

func (*Angine) GetUnconfirmedTxs

func (e *Angine) GetUnconfirmedTxs() []types.Tx

func (*Angine) GetValidators

func (e *Angine) GetValidators() (int, []*types.Validator)

func (*Angine) Height

func (e *Angine) Height() int

func (*Angine) IsNodeValidator

func (e *Angine) IsNodeValidator(pub crypto.PubKey) bool

func (*Angine) P2PHost

func (e *Angine) P2PHost() string

func (*Angine) P2PPort

func (e *Angine) P2PPort() uint16

func (*Angine) PrivValidator

func (e *Angine) PrivValidator() *types.PrivValidator

func (*Angine) ProcessSpecialOP

func (e *Angine) ProcessSpecialOP(tx []byte) error

func (*Angine) RecoverFromCrash

func (e *Angine) RecoverFromCrash(appHash []byte, appBlockHeight int) error

Recover world status Replay all blocks after blockHeight and ensure the result matches the current state.

func (*Angine) RegisterNodeInfo

func (e *Angine) RegisterNodeInfo(ni *p2p.NodeInfo)

func (*Angine) SetSpecialVoteRPC

func (e *Angine) SetSpecialVoteRPC(f func([]byte, *types.Validator) ([]byte, error))

func (*Angine) Start

func (e *Angine) Start() error

func (*Angine) Stop

func (e *Angine) Stop() bool

Stop just wrap around swtich.Stop, which will stop reactors, listeners,etc

type AngineTunes

type AngineTunes struct {
	Runtime string
	Conf    *cfg.MapConfig
}

type ITxCheck

type ITxCheck interface {
	CheckTx(types.Tx) (bool, error)
}

type MempoolFilter

type MempoolFilter struct {
	// contains filtered or unexported fields
}

func NewMempoolFilter

func NewMempoolFilter(f func([]byte) (bool, error)) MempoolFilter

func (MempoolFilter) CheckTx

func (m MempoolFilter) CheckTx(tx types.Tx) (bool, error)

type MockMempool

type MockMempool struct {
}

Updates to the mempool need to be synchronized with committing a block so apps can reset their transient state on Commit

func (MockMempool) Lock

func (m MockMempool) Lock()

func (MockMempool) Unlock

func (m MockMempool) Unlock()

func (MockMempool) Update

func (m MockMempool) Update(height int64, txs []types.Tx)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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