node

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2018 License: LGPL-3.0 Imports: 50 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CoSiTimeout sets the limits of the total timeout in seconds
	CoSiTimeout = 10

	// Packet types
	CoSiSyncMsg    = 0x01
	CoSiAckSyncMsg = 0x02
	RequestSigpart = 0x03

	CommTypeIdentity byte
	CommTypeSecure
)
View Source
const (
	ReceiptsPrefix          = "receipts-"
	OfficialAddress         = "0x7752b42608a0f1943c19fc5802cb027e60b4c911"
	ERR_NODE_ALREADY_RUNING = "node already running"
)
View Source
const (
	OrgRegister byte
	OrgCreate
	OrgJoin
	OrgLeave
	OrgDelete
)
View Source
const (
	BASE_APP_NAME = "metropolis"
)
View Source
const ChainIDArg = "chainid"
View Source
const (
	// metropolis takes query id from 0x30 to 0x3F
	QueryEvents = 0x30
)
View Source
const (
	RPCCollectSpecialVotes uint8 = iota
)

Variables

View Source
var (
	ErrRevertFromBackup = errors.New("revert from backup,not find data")
	ErrDataTransfer     = errors.New("data transfer err")
)
View Source
var (
	// CoSi related transaction tags
	CoSiTag     = []byte{'c', 'o', 's', 0x01}
	CoSiInitTag = []byte{'c', 'o', 's', 0x02}
)
View Source
var (
	EventTag             = []byte{'e', 'v', 't'}
	EventRequestTag      = append(EventTag, 0x01)
	EventSubscribeTag    = append(EventTag, 0x02)
	EventNotificationTag = append(EventTag, 0x03)
	EventUnsubscribeTag  = append(EventTag, 0x04)
	EventConfirmTag      = append(EventTag, 0x05)
	EventMsgTag          = append(EventTag, 0x06)
	EventUploadCodeTag   = append(EventTag, 0x07)
)
View Source
var (
	ErrAccountExisted      = fmt.Errorf("account already existed")
	ErrAccountNotExist     = fmt.Errorf("account not existed")
	ErrInvalidNonce        = fmt.Errorf("invalid nonce")
	ErrInsufficientBalance = fmt.Errorf("balance is lower than the amount to be wired")
)
View Source
var (
	OrgTag        = []byte{'o', 'r', 'g', 0x01}
	OrgCancelTag  = []byte{'o', 'r', 'g', 0x02}
	OrgConfirmTag = []byte{'o', 'r', 'g', 0x03}
)
View Source
var (
	ErrOrgAlreadyIn     = fmt.Errorf("already part the organization")
	ErrOrgFailToStop    = fmt.Errorf("fail to stop organization")
	ErrOrgNotExists     = fmt.Errorf("organization doesn't exist")
	ErrOrgExistsAlready = fmt.Errorf("organization already exists")
)
View Source
var (
	ErrInvalidChainID = errors.New("no such chain id")
	ErrMissingParams  = errors.New("missing params")
)
View Source
var Apps = make(map[string]AppMaker)
View Source
var (
	// ErrUnknownTx is exported because I am not sure if it will be needed outside of this pkg
	ErrUnknownTx = fmt.Errorf("please give me something that I actually know about")
)

Functions

func AppExists

func AppExists(name string) (yes bool)

func BytesToInt

func BytesToInt(bs []byte) (ret int)

func CheckConfNeedInApp

func CheckConfNeedInApp(appName string, conf map[string]interface{}) error

func EncodeEventData

func EncodeEventData(data EventData) ([]byte, error)

func GetCoSiAddress

func GetCoSiAddress(attr AppAttributes) string

func IntToBytes

func IntToBytes(num int) []byte

func IsCoSiInitTx

func IsCoSiInitTx(tx []byte) bool

func IsCoSiTx

func IsCoSiTx(tx []byte) bool

func IsEventNotificationTx

func IsEventNotificationTx(tx []byte) bool

func IsEventRequestTx

func IsEventRequestTx(tx []byte) bool

func IsEventSubscribeTx

func IsEventSubscribeTx(tx []byte) bool

func IsEventTx

func IsEventTx(tx []byte) bool

func IsEventUnsubscribeTx

func IsEventUnsubscribeTx(tx []byte) bool

func IsEventUploadCodeTx

func IsEventUploadCodeTx(tx []byte) bool

func IsOrgCancelTx

func IsOrgCancelTx(tx []byte) bool

func IsOrgConfirmTx

func IsOrgConfirmTx(tx []byte) bool

func IsOrgRelatedTx

func IsOrgRelatedTx(tx []byte) bool

func IsOrgTx

func IsOrgTx(tx []byte) bool

func NewLogger

func NewLogger(conf *viper.Viper) (*zap.Logger, error)

func RunNode

func RunNode(config *viper.Viper)

func RunNodeRet

func RunNodeRet(config *viper.Viper) error

Types

type AggregateInfo

type AggregateInfo struct {
	Pubkey []byte
	Commit []byte
}

type AppAttributes

type AppAttributes = map[string]string

AppAttributes is just a type alias

type AppMaker

type AppMaker func(*zap.Logger, *viper.Viper, crypto.PrivKey) (Application, error)

AppMaker is the signature for functions which take charge of create new instance of applications

type AppName

type AppName string

AppName just wraps around string, maybe we can use the new feat in Go1.9

type AppTool

type AppTool struct {
	agtypes.BaseAppTool
	// contains filtered or unexported fields
}

func (*AppTool) BackupLastBlock

func (t *AppTool) BackupLastBlock(branchName string) error

func (*AppTool) Init

func (t *AppTool) Init(datadir string) error

func (*AppTool) LastHeightHash

func (t *AppTool) LastHeightHash() (def.INT, []byte)

func (*AppTool) SaveNewLastBlock

func (t *AppTool) SaveNewLastBlock(fromHeight def.INT, fromAppHash []byte) error

type Application

type Application interface {
	agtypes.Application
	SetCore(Core)
	GetAttributes() AppAttributes
}

Application embeds types.Application, defines application interface in Civilization

type Broadcaster

type Broadcaster interface {
	BroadcastTx([]byte) error
}

Broadcaster means we can deliver tx in application

type ChainID

type ChainID string

ChainID just wraps around string

type CoSiAppBase

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

CoSiAppBase is the base app for CoSi capability

func NewCoSiAppBase

func NewCoSiAppBase(addr string) CoSiAppBase

func (*CoSiAppBase) CheckTx

func (app *CoSiAppBase) CheckTx(bs []byte) error

func (*CoSiAppBase) ExecuteTx

func (app *CoSiAppBase) ExecuteTx(bs []byte) error

func (*CoSiAppBase) SetCore

func (app *CoSiAppBase) SetCore(core Core)

func (*CoSiAppBase) Setup

func (app *CoSiAppBase) Setup() (string, error)

type CoSiInitTx

type CoSiInitTx struct {
	civiltypes.CivilTx

	Type     string  `json:"type"`
	ChainID  string  `json:"chainid"`
	Receiver []byte  `json:"receiver"`
	TxHash   []byte  `json:"txhash"`
	Height   def.INT `json:"height"`
	Data     []byte  `json:"data"`
}

type CoSiModule

type CoSiModule struct {
	CoSigners      *cosi.Cosigners
	Nonce          uint64
	Pubkeys        []cosiED.PublicKey
	Commitments    []cosi.Commitment
	SignatureParts []cosi.SignaturePart
	Conns          []*p2p.SecretConnection
	// contains filtered or unexported fields
}

func NewCoSiModule

func NewCoSiModule(logger *zap.Logger, privkey crypto.PrivKeyEd25519, validators *agtypes.ValidatorSet) *CoSiModule

func (*CoSiModule) Add

func (cm *CoSiModule) Add(n int)

func (*CoSiModule) Done

func (cm *CoSiModule) Done()

func (*CoSiModule) FollowCoSign

func (cm *CoSiModule) FollowCoSign(leaderAddress string, data []byte) error

FollowCoSign is called by followers in a CoSi round Followers need to know the address of the leader and the actual data to be signed In FollowCoSign, followers will exchange their commitment with the leader and sign the data

func (*CoSiModule) LeadCoSign

func (cm *CoSiModule) LeadCoSign(cosiAddr string, msg []byte) ([]byte, error)

LeadCoSign is called by the leader, which means leader automatically signs positive, otherwise the node should just refuse the CoSiTx without calling LeadCoSign

func (*CoSiModule) Lock

func (cm *CoSiModule) Lock()

func (*CoSiModule) Read

func (cm *CoSiModule) Read(sc *p2p.SecretConnection) ([]byte, error)

func (*CoSiModule) SetLeaderListener

func (cm *CoSiModule) SetLeaderListener(l net.Listener)

func (*CoSiModule) Unlock

func (cm *CoSiModule) Unlock()

func (*CoSiModule) Verify

func (cm *CoSiModule) Verify(sig []byte, msg []byte) bool

Verify the CoSi signature

func (*CoSiModule) Wait

func (cm *CoSiModule) Wait()

func (*CoSiModule) Write

func (cm *CoSiModule) Write(sc *p2p.SecretConnection, data []byte) (int, error)

type CoSiTx

type CoSiTx struct {
	civiltypes.CivilTx

	Type       string  `json:"type"` // what this cosi is for
	Leader     []byte  `json:"leader"`
	LeaderAddr string  `json:"leaderaddr"`
	TxHash     []byte  `json:"txhash"` // relevant tx
	Height     def.INT `json:"height"`
	Data       []byte  `json:"data"` // relevant data
}

type CodeHash

type CodeHash = []byte

type Core

type Core interface {
	Publisher

	IsValidator() bool
	GetPublicKey() (crypto.PubKeyEd25519, bool)
	GetPrivateKey() (crypto.PrivKeyEd25519, bool)
	GetChainID() string
	GetEngine() Engine
	BroadcastTxSuperior([]byte) error
}

Core defines the interface at which an application sees its containing organization

type CosiPacket

type CosiPacket = []byte

func CosiWrapData

func CosiWrapData(data []byte) []CosiPacket

type Engine

type Engine interface {
	GetBlock(def.INT) (*agtypes.BlockCache, *pbtypes.BlockMeta, error)
	GetBlockMeta(def.INT) (*pbtypes.BlockMeta, error)
	GetValidators() (def.INT, *agtypes.ValidatorSet)
	PrivValidator() *agtypes.PrivValidator
	BroadcastTx([]byte) error
	Query(byte, []byte) (interface{}, error)
}

Engine defines the consensus engine

type EventAccount

type EventAccount struct {
	ChainID  string
	MySubers map[string]CodeHash
	MyPubers map[string]CodeHash
	// contains filtered or unexported fields
}

EventAccount abstracts the model used in the EventState, mainly focusing on who am I listening and who is listening me

func NewEventAccount

func NewEventAccount(es *EventState, chainID string) *EventAccount

func (*EventAccount) AddPublisher

func (ea *EventAccount) AddPublisher(pub string, hash CodeHash)

func (*EventAccount) AddSubscriber

func (ea *EventAccount) AddSubscriber(sub string, hash CodeHash)

func (*EventAccount) Copy

func (ea *EventAccount) Copy() *EventAccount

func (*EventAccount) FromBytes

func (ea *EventAccount) FromBytes(bs []byte, es *EventState) error

func (*EventAccount) GetPublishers

func (ea *EventAccount) GetPublishers() map[string]CodeHash

func (*EventAccount) GetSubscribers

func (ea *EventAccount) GetSubscribers() map[string]CodeHash

func (*EventAccount) RemovePublisher

func (ea *EventAccount) RemovePublisher(pub string)

func (*EventAccount) RemoveSubscriber

func (ea *EventAccount) RemoveSubscriber(sub string)

func (*EventAccount) ToBytes

func (ea *EventAccount) ToBytes() []byte

type EventApp

type EventApp interface {
	EventRequestHandle
	EventSubscriber
}

EventApp defines what an app need to implement to support cross-org event communication

type EventAppBase

type EventAppBase struct {
	MetropolisAppBase
	CoSiAppBase
	// contains filtered or unexported fields
}

EventAppBase gives an app the ability to deal with the event system provided by metropolis

func NewEventAppBase

func NewEventAppBase(l *zap.Logger, cosiAddr string) EventAppBase

func (*EventAppBase) CheckTx

func (app *EventAppBase) CheckTx(bs []byte) error

func (*EventAppBase) ConfirmEvent

func (app *EventAppBase) ConfirmEvent(tx *EventNotificationTx) error

ConfirmEvent broadcasts an confirm tx on the organization

func (*EventAppBase) ExecuteTx

func (app *EventAppBase) ExecuteTx(bs []byte, validators *agtypes.ValidatorSet) error

func (*EventAppBase) IncomingEvent

func (app *EventAppBase) IncomingEvent(_ string, _ def.INT) bool

IncomingEvent is set true by default

func (*EventAppBase) PublishEvent

func (app *EventAppBase) PublishEvent(data []EventData, block *agtypes.BlockCache) error

func (*EventAppBase) SetCoSiAddr

func (app *EventAppBase) SetCoSiAddr(addr string)

func (*EventAppBase) SetCore

func (app *EventAppBase) SetCore(core Core)

func (*EventAppBase) Setup

func (app *EventAppBase) Setup() (string, error)

func (*EventAppBase) Start

func (app *EventAppBase) Start() (string, error)

func (*EventAppBase) Stop

func (app *EventAppBase) Stop() error

func (*EventAppBase) SupportCoSiTx

func (app *EventAppBase) SupportCoSiTx()

SupportCoSiTx is just an empty token

type EventConfirmTx

type EventConfirmTx struct {
	civiltypes.CivilTx
	Source   string    `json:"source"`
	EventID  string    `json:"eventid"`
	DataHash []byte    `json:"datahash"`
	TxHash   []byte    `json:"txhash"`
	Time     time.Time `json:"time"`
}

type EventData

type EventData map[string]interface{}

func DecodeEventData

func DecodeEventData(bs []byte) (EventData, error)

type EventMsgTx

type EventMsgTx struct {
	civiltypes.CivilTx
	Listener string    `json:"listener"`
	EventID  string    `json:"eventid"`
	DataHash []byte    `json:"datahash"`
	Msg      []byte    `json:"msg"`
	Time     time.Time `json:"time"`
}

type EventNotificationTx

type EventNotificationTx struct {
	civiltypes.CivilTx

	Listener  string    `json:"listener"`
	Source    string    `json:"source"`
	Height    def.INT   `json:"height"`
	DataHash  []byte    `json:"datahash"`
	RelatedTx []byte    `json:"relatedtx"`
	Time      time.Time `json:"time"`
}

type EventRequestHandle

type EventRequestHandle interface {
	SupportCoSiTx()
}

EventRequestHandle defines just one empty method, SupportCoSiTx, as a token Event system will need the Ed25519 CoSi

type EventRequestTx

type EventRequestTx struct {
	civiltypes.CivilTx

	Source       string    `json:"source"`
	Listener     string    `json:"listener"`
	Time         time.Time `json:"time"`
	SourceHash   []byte    `json:"source_hash"`
	ListenerHash []byte    `json:"listener_hash"`
}

type EventState

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

EventState manages event subscription relationships between subchains

func NewEventState

func NewEventState(database db.DB) *EventState

func (*EventState) Commit

func (es *EventState) Commit() ([]byte, error)

func (*EventState) Copy

func (es *EventState) Copy() *EventState

func (*EventState) CreateAccount

func (es *EventState) CreateAccount(chainID string) (accnt *EventAccount, err error)

func (*EventState) ExistAccount

func (es *EventState) ExistAccount(chainID string) bool

func (*EventState) GetAccount

func (es *EventState) GetAccount(chainID string) (accnt *EventAccount, err error)

func (*EventState) Load

func (es *EventState) Load(root []byte)

func (*EventState) Lock

func (es *EventState) Lock()

func (*EventState) ModifyAccount

func (es *EventState) ModifyAccount(a *EventAccount)

func (*EventState) Reload

func (es *EventState) Reload(root []byte)

func (*EventState) Unlock

func (es *EventState) Unlock()

type EventSubscribeTx

type EventSubscribeTx struct {
	civiltypes.CivilTx

	Source      string    `json:"source"`
	Threshold   int       `json:"threshold"`
	TxHash      []byte    `json:"txhash"`
	Time        time.Time `json:"time"`
	SignData    []byte    `json:"signdata"`
	CoSignature []byte    `json:"cosignature"`
}

type EventSubscriber

type EventSubscriber interface {
	// IncomingEvent returns App's decision about whether to fetch this new event
	IncomingEvent(from string, height def.INT) bool

	ConfirmEvent(tx *EventNotificationTx) error

	// HandleEvent will process the event, you can do whatever you like. This will be running in its own routine
	HandleEvent(data EventData, tx *EventNotificationTx)
}

EventSubscriber defines interfaces for being compatible with event system

type EventUnsubscribeTx

type EventUnsubscribeTx struct {
	civiltypes.CivilTx

	Source   string    `json:"source"`
	Listener string    `json:"listener"`
	Proof    []byte    `json:"proof"`
	Time     time.Time `json:"time"`
}

type EventUploadCodeTx

type EventUploadCodeTx struct {
	civiltypes.CivilTx
	Source string    `json:"source"`
	Owner  string    `json:"owner"`
	Code   string    `json:"code"`
	Time   time.Time `json:"time"`
}

type EventWarehouse

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

EventWarehouse stores those event data which are published but still not fetched by their target subchains.

EventWarehouse.database is the storage. EventWarehouse.state is kinda like index for the storage.

func NewEventWarehouse

func NewEventWarehouse(database db.DB) *EventWarehouse

NewEventWarehouse constructs a new EventWarehouse and returns a pointer to the instance

func (*EventWarehouse) Batch

func (ew *EventWarehouse) Batch() db.Batch

Batch just wraps about db.NewBatch

func (*EventWarehouse) Fetch

func (ew *EventWarehouse) Fetch(subID, pubID string, height def.INT) ([]byte, error)

func (*EventWarehouse) Flush

func (ew *EventWarehouse) Flush(batch db.Batch)

Flush persists db writes and ec.state changes

func (*EventWarehouse) GenerateID

func (ew *EventWarehouse) GenerateID(subID, pubID string, height def.INT) []byte

GenerateID generates wellformed key used in EventWarehouse

func (*EventWarehouse) Pop

func (ew *EventWarehouse) Pop(subID, pubID string, height def.INT) ([]byte, error)

Pop makes sure the one event can only be fetched once by deleting after fetched

func (*EventWarehouse) Push

func (ew *EventWarehouse) Push(batch db.Batch, subID, pubID string, height def.INT, data []byte)

Push will add new record to both EventWarehouseState and EventWarehouse

type EventWarehouseState

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

EventWarehouseState contains subscriberID-publisherID : []heights

func (*EventWarehouseState) Append

func (ews *EventWarehouseState) Append(subID, pubID string, height def.INT) []def.INT

func (*EventWarehouseState) Get

func (ews *EventWarehouseState) Get(subID, pubID string) ([]def.INT, error)

func (*EventWarehouseState) Set

func (ews *EventWarehouseState) Set(subID, pubID string, heights []def.INT)

func (*EventWarehouseState) ToBytes

func (ews *EventWarehouseState) ToBytes() ([]byte, error)

type Hashable

type Hashable interface {
	Serializable
}

Hashable aliases Serializable

type IMetropolisApp

type IMetropolisApp interface {
	GetAttribute(string) (string, bool)
	GetAttributes() AppAttributes
	SetAttributes(AppAttributes)
	PushAttribute(string, string)
	AttributeExists(string) bool
}

type IdentityAck

type IdentityAck struct {
	Type      byte   `json:"type"`
	PubKey    []byte `json:"pubkey"`
	Signature []byte `json:"signature"`
}

type LastBlockInfo

type LastBlockInfo struct {
	Height def.INT `msgpack:"height"`
	// hash from the top level state
	Hash []byte `msgpack:"hash"`
}

LastBlockInfo is just a must for every angine-based application

func NewLastBlockInfo

func NewLastBlockInfo() *LastBlockInfo

NewLastBlockInfo just a convience to generate an empty LastBlockInfo

type Metropolis

type Metropolis struct {
	agtypes.BaseApplication

	// Organization
	OrgStateDB db.DB
	// OrgState is a DL that keeps tracks of subchains' state
	OrgState *OrgState
	OrgApps  map[ChainID]AppName
	// Orgs contains all the subchains this node is effectively in
	Orgs map[ChainID]*OrgNode
	// TODO: persist onto disk
	PendingOrgTxs map[string]*OrgTx

	// Events
	EventStateDB   db.DB
	EventState     *EventState
	EventWarehouse *EventWarehouse
	EventCodeBase  db.DB
	// TODO: persist onto disk
	PendingEventRequestTxs map[string]*EventRequestTx
	// contains filtered or unexported fields
}

Metropolis defines the application

func NewMetropolis

func NewMetropolis(logger *zap.Logger, conf *viper.Viper) *Metropolis

NewMetropolis initialize all the necessary parts of the application: 1. state of metropolis 2. init BaseApplication 3. open databases and generate orgstate, eventstate and so on 4. set up the angine hooks

func (*Metropolis) BroadcastTx

func (met *Metropolis) BroadcastTx(tx []byte) error

BroadcastTx just passes the transaction into core

func (*Metropolis) CheckTx

func (met *Metropolis) CheckTx(bs []byte) error

CheckTx just contains a big switch which multiplex different kinds of transactions supported

func (*Metropolis) CodeExists

func (met *Metropolis) CodeExists(codehash []byte) bool

func (*Metropolis) CompatibleWithAngine

func (met *Metropolis) CompatibleWithAngine()

CompatibleWithAngine just exists to satisfy types.Application

func (*Metropolis) ExecuteTx

func (met *Metropolis) ExecuteTx(block *agtypes.BlockCache, bs []byte, txIndex int) (validtx []byte, err error)

ExecuteTx execute tx one by one in the loop, without lock, so should always be called between Lock() and Unlock() on the *stateDup

func (*Metropolis) GetAngineHooks

func (met *Metropolis) GetAngineHooks() agtypes.Hooks

GetAngineHooks returns the hooks we defined for angine to grasp

func (*Metropolis) GetAttributes

func (met *Metropolis) GetAttributes() map[string]string

func (*Metropolis) GetNodePubKey

func (met *Metropolis) GetNodePubKey() crypto.PubKey

GetNodePubKey gets our universal public key

func (*Metropolis) GetOrg

func (met *Metropolis) GetOrg(id string) (*OrgNode, error)

GetOrg gets the orgnode associated to the chainid, or gives an error if we are not connected to the chain

func (*Metropolis) Hash

func (met *Metropolis) Hash() []byte

Hash is merely a wrapper of MetropolisState.Hash

func (*Metropolis) Info

func (met *Metropolis) Info() (resInfo agtypes.ResultInfo)

Info gives information about the application in general

func (*Metropolis) IsTxKnown

func (met *Metropolis) IsTxKnown(bs []byte) bool

IsTxKnown is a fast way to identify txs unknown

func (*Metropolis) Load

func (met *Metropolis) Load(lb *LastBlockInfo) error

Load gets all those ledgers have been persisted back alive by a metropolisstate hash

func (*Metropolis) Lock

func (met *Metropolis) Lock()

Lock locks Metropolis universally

func (*Metropolis) OnCommit

func (met *Metropolis) OnCommit(height, round def.INT, block *agtypes.BlockCache) (interface{}, error)

OnCommit persists state that we define to be consistent in a cross-block way

func (*Metropolis) OnExecute

func (met *Metropolis) OnExecute(height, round def.INT, block *agtypes.BlockCache) (interface{}, error)

OnExecute would not care about Block.ExTxs

func (*Metropolis) PublishEvent

func (met *Metropolis) PublishEvent(chainID string, block *agtypes.BlockCache, data []EventData, relatedTxHash []byte) error

PublishEvent implements node.Publisher interface. all Apps running on this node call this Publish to publish event if they want now we just publish the event with no difference, maybe we could offer some customized subscription

func (*Metropolis) Query

func (met *Metropolis) Query(query []byte) agtypes.Result

Query now gives the ability to query transaction execution result with the transaction hash

func (*Metropolis) RemoveOrg

func (met *Metropolis) RemoveOrg(id string) error

RemoveOrg wraps atomic operations needed to be done when node gets removed from an organization

func (*Metropolis) SetCore

func (met *Metropolis) SetCore(c Core)

SetCore gives Metropolis a way to make some calls to the node running underneath it is more abstractive than SetNode, which I am planning to deprecate.

func (*Metropolis) SetNode

func (met *Metropolis) SetNode(n *Node)

SetNode

func (*Metropolis) SetOption

func (met *Metropolis) SetOption()

SetOption can dynamicly change some options of the application

func (*Metropolis) SetOrg

func (met *Metropolis) SetOrg(chainID, appname string, o *OrgNode)

SetOrg wraps some atomic operations that need to be done when this node create/join an organization

func (*Metropolis) Start

func (met *Metropolis) Start() error

Start will restore organization according to orgtx history

func (*Metropolis) Stop

func (met *Metropolis) Stop()

Stop stops all still running organization

func (*Metropolis) Unlock

func (met *Metropolis) Unlock()

Unlock undos what Lock does

type MetropolisAppBase

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

MetropolisAppBase is the base struct every app in annchain should embed

func NewMetropolisAppBase

func NewMetropolisAppBase() MetropolisAppBase

func (*MetropolisAppBase) AttributeExists

func (app *MetropolisAppBase) AttributeExists(key string) bool

func (*MetropolisAppBase) GetAttribute

func (app *MetropolisAppBase) GetAttribute(key string) (val string, exists bool)

func (*MetropolisAppBase) GetAttributes

func (app *MetropolisAppBase) GetAttributes() AppAttributes

func (*MetropolisAppBase) PushAttribute

func (app *MetropolisAppBase) PushAttribute(key, val string)

func (*MetropolisAppBase) SetAttributes

func (app *MetropolisAppBase) SetAttributes(attrs AppAttributes)

func (*MetropolisAppBase) SetCore

func (app *MetropolisAppBase) SetCore(c Core)

func (*MetropolisAppBase) Start

func (app *MetropolisAppBase) Start() error

func (*MetropolisAppBase) Stop

func (app *MetropolisAppBase) Stop() error

type MetropolisState

type MetropolisState struct {
	OrgStateHash   []byte
	OrgHeights     []def.INT
	EventStateHash []byte
}

MetropolisState abstracts the structure of the information that we need to make the application consistency verifiable

func (*MetropolisState) FromBytes

func (ms *MetropolisState) FromBytes(bs []byte) error

func (*MetropolisState) Hash

func (ms *MetropolisState) Hash() []byte

func (*MetropolisState) ToBytes

func (ms *MetropolisState) ToBytes() []byte

type Node

type Node struct {
	MainChainID string
	MainOrg     *OrgNode
	// contains filtered or unexported fields
}

func NewNode

func NewNode(conf *viper.Viper) *Node

func (*Node) GetConf

func (n *Node) GetConf() *viper.Viper

func (*Node) NodeInfo

func (n *Node) NodeInfo() *p2p.NodeInfo

func (*Node) PrivValidator

func (n *Node) PrivValidator() *types.PrivValidator

func (*Node) Start

func (n *Node) Start() error

Call Start() after adding the listeners.

func (*Node) StartRPC

func (n *Node) StartRPC() ([]net.Listener, error)

func (*Node) Stop

func (n *Node) Stop()

type OrgAccount

type OrgAccount struct {
	ChainID string                       `json:"chainid"`
	PubKey  []byte                       `json:"pubkey"`
	Nonce   uint64                       `json:"nonce"`
	Balance int64                        `json:"balance"`
	Count   int                          `json:"count"`
	Nodes   map[string]map[string]string `json:"nodes"`
	// contains filtered or unexported fields
}

OrgAccount abstracts account model Pay attention that you have to call orgstate.ModifyAccount when you change anything in the account otherwise, your changes won't live across commits.

func NewOrgAccount

func NewOrgAccount(state *OrgState, chainID string, pubkey []byte, balance int64) *OrgAccount

NewOrgAccount also binds org state with the newly created account

func (*OrgAccount) AddNode

func (oa *OrgAccount) AddNode(p crypto.PubKey, attr map[string]string) error

func (*OrgAccount) Copy

func (oa *OrgAccount) Copy() *OrgAccount

func (*OrgAccount) FromBytes

func (oa *OrgAccount) FromBytes(bytes []byte, state *OrgState) error

FromBytes also restores the connection between the account and the org state

func (*OrgAccount) GetBalance

func (oa *OrgAccount) GetBalance() int64

func (*OrgAccount) GetChainID

func (oa *OrgAccount) GetChainID() string

func (*OrgAccount) GetNodes

func (oa *OrgAccount) GetNodes() map[string]map[string]string

func (*OrgAccount) GetNonce

func (oa *OrgAccount) GetNonce() uint64

func (*OrgAccount) GetPubkey

func (oa *OrgAccount) GetPubkey() []byte

func (*OrgAccount) GetPubkeyString

func (oa *OrgAccount) GetPubkeyString() string

func (*OrgAccount) RemoveNode

func (oa *OrgAccount) RemoveNode(p crypto.PubKey) error

func (*OrgAccount) SetBalance

func (oa *OrgAccount) SetBalance(b int64)

func (*OrgAccount) SetNonce

func (oa *OrgAccount) SetNonce(n uint64)

func (*OrgAccount) ToBytes

func (oa *OrgAccount) ToBytes() []byte

type OrgCancelTx

type OrgCancelTx struct {
	civiltypes.CivilTx

	TxHash []byte    `json:"txhash"`
	Time   time.Time `json:"time"`
}

OrgCancelTx cancels pending OrgTx

type OrgConfirmTx

type OrgConfirmTx struct {
	civiltypes.CivilTx

	ChainID    string            `json:"chainid"`
	Act        byte              `json:"act"`
	Validators [][]byte          `json:"validators"` // unused
	Time       time.Time         `json:"time"`
	TxHash     []byte            `json:"txhash"`
	Attributes map[string]string `json:"attribute"` // some additionals which we wanna inform others
}

OrgConfirmTx comes from a former OrgTx target node and on receiving every node write their org ledger down about the change caused by the OrgTx confirmed

type OrgNode

type OrgNode struct {
	Superior    Superior
	Angine      *angine.Angine
	AngineTune  *angine.Tunes
	Application agtypes.Application
	GenesisDoc  *agtypes.GenesisDoc
	// contains filtered or unexported fields
}

OrgNode implements types.Core

func NewOrgNode

func NewOrgNode(logger *zap.Logger, appName string, conf *viper.Viper, metro *Metropolis) *OrgNode

func (*OrgNode) BroadcastTxSuperior

func (o *OrgNode) BroadcastTxSuperior(tx []byte) error

func (*OrgNode) CodeExists

func (o *OrgNode) CodeExists(codehash []byte) bool

func (*OrgNode) GetAppName

func (o *OrgNode) GetAppName() string

func (*OrgNode) GetChainID

func (o *OrgNode) GetChainID() string

func (*OrgNode) GetEngine

func (o *OrgNode) GetEngine() Engine

func (*OrgNode) GetPrivateKey

func (o *OrgNode) GetPrivateKey() (r crypto.PrivKeyEd25519, b bool)

func (*OrgNode) GetPublicKey

func (o *OrgNode) GetPublicKey() (r crypto.PubKeyEd25519, b bool)

func (*OrgNode) IsRunning

func (o *OrgNode) IsRunning() bool

func (*OrgNode) IsValidator

func (o *OrgNode) IsValidator() bool

func (*OrgNode) PublishEvent

func (o *OrgNode) PublishEvent(from string, block *agtypes.BlockCache, data []EventData, txhash []byte) error

func (*OrgNode) Start

func (o *OrgNode) Start() error

func (*OrgNode) Stop

func (o *OrgNode) Stop() bool

type OrgState

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

func NewOrgState

func NewOrgState(database db.DB) *OrgState

func (*OrgState) CanWire

func (os *OrgState) CanWire(fromAcc *OrgAccount, amount int64, nonce uint64, deliver bool) (bool, error)

CanWire should be called between state.Lock() and state.Unlock()

func (*OrgState) Commit

func (os *OrgState) Commit() ([]byte, error)

Commit returns the new root bytes

func (*OrgState) Copy

func (os *OrgState) Copy() *OrgState

func (*OrgState) CreateAccount

func (os *OrgState) CreateAccount(chainID string, balance int64) (accnt *OrgAccount, err error)

func (*OrgState) ExistAccount

func (os *OrgState) ExistAccount(chainID string) bool

func (*OrgState) GetAccount

func (os *OrgState) GetAccount(chainID string) (accnt *OrgAccount, err error)

func (*OrgState) Load

func (os *OrgState) Load(root []byte)

Load dumps all the buffer, start every thing from a clean state

func (*OrgState) Lock

func (os *OrgState) Lock()

func (*OrgState) ModifyAccount

func (os *OrgState) ModifyAccount(account *OrgAccount)

ModifyAccount puts accounts into dirty cache and they will be persisted during commit

func (*OrgState) Reload

func (os *OrgState) Reload(root []byte)

Reload works the same as Load, just for semantic purpose

func (*OrgState) RemoveAccount

func (os *OrgState) RemoveAccount(chainID string) bool

RemoveAccount acts in a sync-block way remove related bufferred data and remove the account from db immediately

func (*OrgState) Unlock

func (os *OrgState) Unlock()

func (*OrgState) Wire

func (os *OrgState) Wire(from []byte, to []byte, amount int64, nonce uint64) (int64, error)

type OrgTx

type OrgTx struct {
	civiltypes.CivilTx

	App     string                 `json:"app"`
	Act     byte                   `json:"act"`
	ChainID string                 `json:"chainid"`
	Genesis types.GenesisDoc       `json:"genesis"`
	Config  map[string]interface{} `json:"config"`
	Time    time.Time              `json:"time"`
}

OrgTx contains action and information about a change in the org ledger that might happen after confirmation

type Publisher

type Publisher interface {
	// PublishEvent
	// if data is neither tx nor []tx, the related tx hash should be given accordingly
	PublishEvent(from string, block *agtypes.BlockCache, data []EventData, txhash []byte) error
	CodeExists([]byte) bool
}

Publisher means that we can publish events

type RPCNode

type RPCNode interface {
	GetOrg(string) (*OrgNode, error)
	Height() def.INT
	GetBlock(height def.INT) (*agtypes.BlockCache, *pbtypes.BlockMeta)
	BroadcastTx(tx []byte) error
	BroadcastTxCommit(tx []byte) error
	FlushMempool()
	GetValidators() (def.INT, []*agtypes.Validator)
	GetP2PNetInfo() (bool, []string, []*agtypes.Peer)
	GetNumPeers() int
	GetConsensusStateInfo() (string, []string)
	GetNumUnconfirmedTxs() int
	GetUnconfirmedTxs() []agtypes.Tx
	IsNodeValidator(pub crypto.PubKey) bool
	GetBlacklist() []string
}

RPCNode define the node's abilities provided for rpc calls

type Serializable

type Serializable interface {
	ToBytes() ([]byte, error)
}

Serializable transforms to bytes

type Superior

type Superior interface {
	Publisher
	Broadcaster
}

Superior defines the application on the upper level, e.g. Metropolis

type Unserializable

type Unserializable interface {
	FromBytes(bs []byte)
}

Unserializable transforms from bytes

Jump to

Keyboard shortcuts

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