Documentation ¶
Index ¶
- Constants
- Variables
- func AppExists(name string) (yes bool)
- func BytesToInt(bs []byte) (ret int)
- func CheckConfNeedInApp(appName string, conf map[string]interface{}) error
- func EncodeEventData(data EventData) ([]byte, error)
- func GetCoSiAddress(attr AppAttributes) string
- func IntToBytes(num int) []byte
- func IsCoSiInitTx(tx []byte) bool
- func IsCoSiTx(tx []byte) bool
- func IsEventNotificationTx(tx []byte) bool
- func IsEventRequestTx(tx []byte) bool
- func IsEventSubscribeTx(tx []byte) bool
- func IsEventTx(tx []byte) bool
- func IsEventUnsubscribeTx(tx []byte) bool
- func IsEventUploadCodeTx(tx []byte) bool
- func IsOrgCancelTx(tx []byte) bool
- func IsOrgConfirmTx(tx []byte) bool
- func IsOrgRelatedTx(tx []byte) bool
- func IsOrgTx(tx []byte) bool
- func NewLogger(conf *viper.Viper) (*zap.Logger, error)
- func RunNode(config *viper.Viper)
- func RunNodeRet(config *viper.Viper) error
- type AggregateInfo
- type AppAttributes
- type AppMaker
- type AppName
- type AppTool
- type Application
- type Broadcaster
- type ChainID
- type CoSiAppBase
- type CoSiInitTx
- type CoSiModule
- func (cm *CoSiModule) Add(n int)
- func (cm *CoSiModule) Done()
- func (cm *CoSiModule) FollowCoSign(leaderAddress string, data []byte) error
- func (cm *CoSiModule) LeadCoSign(cosiAddr string, msg []byte) ([]byte, error)
- func (cm *CoSiModule) Lock()
- func (cm *CoSiModule) Read(sc *p2p.SecretConnection) ([]byte, error)
- func (cm *CoSiModule) SetLeaderListener(l net.Listener)
- func (cm *CoSiModule) Unlock()
- func (cm *CoSiModule) Verify(sig []byte, msg []byte) bool
- func (cm *CoSiModule) Wait()
- func (cm *CoSiModule) Write(sc *p2p.SecretConnection, data []byte) (int, error)
- type CoSiTx
- type CodeHash
- type Core
- type CosiPacket
- type Engine
- type EventAccount
- func (ea *EventAccount) AddPublisher(pub string, hash CodeHash)
- func (ea *EventAccount) AddSubscriber(sub string, hash CodeHash)
- func (ea *EventAccount) Copy() *EventAccount
- func (ea *EventAccount) FromBytes(bs []byte, es *EventState) error
- func (ea *EventAccount) GetPublishers() map[string]CodeHash
- func (ea *EventAccount) GetSubscribers() map[string]CodeHash
- func (ea *EventAccount) RemovePublisher(pub string)
- func (ea *EventAccount) RemoveSubscriber(sub string)
- func (ea *EventAccount) ToBytes() []byte
- type EventApp
- type EventAppBase
- func (app *EventAppBase) CheckTx(bs []byte) error
- func (app *EventAppBase) ConfirmEvent(tx *EventNotificationTx) error
- func (app *EventAppBase) ExecuteTx(bs []byte, validators *agtypes.ValidatorSet) error
- func (app *EventAppBase) IncomingEvent(_ string, _ def.INT) bool
- func (app *EventAppBase) PublishEvent(data []EventData, block *agtypes.BlockCache) error
- func (app *EventAppBase) SetCoSiAddr(addr string)
- func (app *EventAppBase) SetCore(core Core)
- func (app *EventAppBase) Setup() (string, error)
- func (app *EventAppBase) Start() (string, error)
- func (app *EventAppBase) Stop() error
- func (app *EventAppBase) SupportCoSiTx()
- type EventConfirmTx
- type EventData
- type EventMsgTx
- type EventNotificationTx
- type EventRequestHandle
- type EventRequestTx
- type EventState
- func (es *EventState) Commit() ([]byte, error)
- func (es *EventState) Copy() *EventState
- func (es *EventState) CreateAccount(chainID string) (accnt *EventAccount, err error)
- func (es *EventState) ExistAccount(chainID string) bool
- func (es *EventState) GetAccount(chainID string) (accnt *EventAccount, err error)
- func (es *EventState) Load(root []byte)
- func (es *EventState) Lock()
- func (es *EventState) ModifyAccount(a *EventAccount)
- func (es *EventState) Reload(root []byte)
- func (es *EventState) Unlock()
- type EventSubscribeTx
- type EventSubscriber
- type EventUnsubscribeTx
- type EventUploadCodeTx
- type EventWarehouse
- func (ew *EventWarehouse) Batch() db.Batch
- func (ew *EventWarehouse) Fetch(subID, pubID string, height def.INT) ([]byte, error)
- func (ew *EventWarehouse) Flush(batch db.Batch)
- func (ew *EventWarehouse) GenerateID(subID, pubID string, height def.INT) []byte
- func (ew *EventWarehouse) Pop(subID, pubID string, height def.INT) ([]byte, error)
- func (ew *EventWarehouse) Push(batch db.Batch, subID, pubID string, height def.INT, data []byte)
- type EventWarehouseState
- type Hashable
- type IMetropolisApp
- type IdentityAck
- type LastBlockInfo
- type Metropolis
- func (met *Metropolis) BroadcastTx(tx []byte) error
- func (met *Metropolis) CheckTx(bs []byte) error
- func (met *Metropolis) CodeExists(codehash []byte) bool
- func (met *Metropolis) CompatibleWithAngine()
- func (met *Metropolis) ExecuteTx(block *agtypes.BlockCache, bs []byte, txIndex int) (validtx []byte, err error)
- func (met *Metropolis) GetAngineHooks() agtypes.Hooks
- func (met *Metropolis) GetAttributes() map[string]string
- func (met *Metropolis) GetNodePubKey() crypto.PubKey
- func (met *Metropolis) GetOrg(id string) (*OrgNode, error)
- func (met *Metropolis) Hash() []byte
- func (met *Metropolis) Info() (resInfo agtypes.ResultInfo)
- func (met *Metropolis) IsTxKnown(bs []byte) bool
- func (met *Metropolis) Load(lb *LastBlockInfo) error
- func (met *Metropolis) Lock()
- func (met *Metropolis) OnCommit(height, round def.INT, block *agtypes.BlockCache) (interface{}, error)
- func (met *Metropolis) OnExecute(height, round def.INT, block *agtypes.BlockCache) (interface{}, error)
- func (met *Metropolis) PublishEvent(chainID string, block *agtypes.BlockCache, data []EventData, ...) error
- func (met *Metropolis) Query(query []byte) agtypes.Result
- func (met *Metropolis) RemoveOrg(id string) error
- func (met *Metropolis) SetCore(c Core)
- func (met *Metropolis) SetNode(n *Node)
- func (met *Metropolis) SetOption()
- func (met *Metropolis) SetOrg(chainID, appname string, o *OrgNode)
- func (met *Metropolis) Start() error
- func (met *Metropolis) Stop()
- func (met *Metropolis) Unlock()
- type MetropolisAppBase
- func (app *MetropolisAppBase) AttributeExists(key string) bool
- func (app *MetropolisAppBase) GetAttribute(key string) (val string, exists bool)
- func (app *MetropolisAppBase) GetAttributes() AppAttributes
- func (app *MetropolisAppBase) PushAttribute(key, val string)
- func (app *MetropolisAppBase) SetAttributes(attrs AppAttributes)
- func (app *MetropolisAppBase) SetCore(c Core)
- func (app *MetropolisAppBase) Start() error
- func (app *MetropolisAppBase) Stop() error
- type MetropolisState
- type Node
- type OrgAccount
- func (oa *OrgAccount) AddNode(p crypto.PubKey, attr map[string]string) error
- func (oa *OrgAccount) Copy() *OrgAccount
- func (oa *OrgAccount) FromBytes(bytes []byte, state *OrgState) error
- func (oa *OrgAccount) GetBalance() int64
- func (oa *OrgAccount) GetChainID() string
- func (oa *OrgAccount) GetNodes() map[string]map[string]string
- func (oa *OrgAccount) GetNonce() uint64
- func (oa *OrgAccount) GetPubkey() []byte
- func (oa *OrgAccount) GetPubkeyString() string
- func (oa *OrgAccount) RemoveNode(p crypto.PubKey) error
- func (oa *OrgAccount) SetBalance(b int64)
- func (oa *OrgAccount) SetNonce(n uint64)
- func (oa *OrgAccount) ToBytes() []byte
- type OrgCancelTx
- type OrgConfirmTx
- type OrgNode
- func (o *OrgNode) BroadcastTxSuperior(tx []byte) error
- func (o *OrgNode) CodeExists(codehash []byte) bool
- func (o *OrgNode) GetAppName() string
- func (o *OrgNode) GetChainID() string
- func (o *OrgNode) GetEngine() Engine
- func (o *OrgNode) GetPrivateKey() (r crypto.PrivKeyEd25519, b bool)
- func (o *OrgNode) GetPublicKey() (r crypto.PubKeyEd25519, b bool)
- func (o *OrgNode) IsRunning() bool
- func (o *OrgNode) IsValidator() bool
- func (o *OrgNode) PublishEvent(from string, block *agtypes.BlockCache, data []EventData, txhash []byte) error
- func (o *OrgNode) Start() error
- func (o *OrgNode) Stop() bool
- type OrgState
- func (os *OrgState) CanWire(fromAcc *OrgAccount, amount int64, nonce uint64, deliver bool) (bool, error)
- func (os *OrgState) Commit() ([]byte, error)
- func (os *OrgState) Copy() *OrgState
- func (os *OrgState) CreateAccount(chainID string, balance int64) (accnt *OrgAccount, err error)
- func (os *OrgState) ExistAccount(chainID string) bool
- func (os *OrgState) GetAccount(chainID string) (accnt *OrgAccount, err error)
- func (os *OrgState) Load(root []byte)
- func (os *OrgState) Lock()
- func (os *OrgState) ModifyAccount(account *OrgAccount)
- func (os *OrgState) Reload(root []byte)
- func (os *OrgState) RemoveAccount(chainID string) bool
- func (os *OrgState) Unlock()
- func (os *OrgState) Wire(from []byte, to []byte, amount int64, nonce uint64) (int64, error)
- type OrgTx
- type Publisher
- type RPCNode
- type Serializable
- type Superior
- type Unserializable
Constants ¶
const ( // CoSiTimeout sets the limits of the total timeout in seconds CoSiTimeout = 10 // Packet types CoSiSyncMsg = 0x01 CoSiAckSyncMsg = 0x02 RequestSigpart = 0x03 CommTypeIdentity byte CommTypeSecure )
const ( ReceiptsPrefix = "receipts-" OfficialAddress = "0x7752b42608a0f1943c19fc5802cb027e60b4c911" ERR_NODE_ALREADY_RUNING = "node already running" )
const ( OrgRegister byte OrgCreate OrgJoin OrgLeave OrgDelete )
const (
BASE_APP_NAME = "metropolis"
)
const ChainIDArg = "chainid"
const (
// metropolis takes query id from 0x30 to 0x3F
QueryEvents = 0x30
)
const (
RPCCollectSpecialVotes uint8 = iota
)
Variables ¶
var ( ErrRevertFromBackup = errors.New("revert from backup,not find data") ErrDataTransfer = errors.New("data transfer err") )
var ( // CoSi related transaction tags CoSiTag = []byte{'c', 'o', 's', 0x01} CoSiInitTag = []byte{'c', 'o', 's', 0x02} )
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) )
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") )
var ( OrgTag = []byte{'o', 'r', 'g', 0x01} OrgCancelTag = []byte{'o', 'r', 'g', 0x02} OrgConfirmTag = []byte{'o', 'r', 'g', 0x03} )
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") )
var ( ErrInvalidChainID = errors.New("no such chain id") ErrMissingParams = errors.New("missing params") )
var Apps = make(map[string]AppMaker)
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 BytesToInt ¶
func CheckConfNeedInApp ¶
func EncodeEventData ¶
func GetCoSiAddress ¶
func GetCoSiAddress(attr AppAttributes) string
func IntToBytes ¶
func IsCoSiInitTx ¶
func IsEventNotificationTx ¶
func IsEventRequestTx ¶
func IsEventSubscribeTx ¶
func IsEventUnsubscribeTx ¶
func IsEventUploadCodeTx ¶
func IsOrgCancelTx ¶
func IsOrgConfirmTx ¶
func IsOrgRelatedTx ¶
func RunNodeRet ¶
Types ¶
type AggregateInfo ¶
type AppMaker ¶
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 ¶
type Application ¶
type Application interface { agtypes.Application SetCore(Core) GetAttributes() AppAttributes }
Application embeds types.Application, defines application interface in Civilization
type Broadcaster ¶
Broadcaster means we can deliver tx in application
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 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()
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 EventMsgTx ¶
type EventNotificationTx ¶
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 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 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 EventUploadCodeTx ¶
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) 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
type EventWarehouseState ¶
type EventWarehouseState struct {
// contains filtered or unexported fields
}
EventWarehouseState contains subscriberID-publisherID : []heights
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 IMetropolisApp ¶
type IMetropolisApp interface { GetAttribute(string) (string, bool) GetAttributes() AppAttributes SetAttributes(AppAttributes) PushAttribute(string, string) AttributeExists(string) bool }
type IdentityAck ¶
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) 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) 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
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 ¶
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 ¶
func (*Node) PrivValidator ¶
func (n *Node) PrivValidator() *types.PrivValidator
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) 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 (*OrgNode) BroadcastTxSuperior ¶
func (*OrgNode) CodeExists ¶
func (*OrgNode) GetAppName ¶
func (*OrgNode) GetChainID ¶
func (*OrgNode) GetPrivateKey ¶
func (*OrgNode) GetPublicKey ¶
func (*OrgNode) IsValidator ¶
func (*OrgNode) PublishEvent ¶
type OrgState ¶
type OrgState struct {
// contains filtered or unexported fields
}
func NewOrgState ¶
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) CreateAccount ¶
func (os *OrgState) CreateAccount(chainID string, balance int64) (accnt *OrgAccount, err error)
func (*OrgState) ExistAccount ¶
func (*OrgState) GetAccount ¶
func (os *OrgState) GetAccount(chainID string) (accnt *OrgAccount, err error)
func (*OrgState) ModifyAccount ¶
func (os *OrgState) ModifyAccount(account *OrgAccount)
ModifyAccount puts accounts into dirty cache and they will be persisted during commit
func (*OrgState) RemoveAccount ¶
RemoveAccount acts in a sync-block way remove related bufferred data and remove the account from db immediately
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 ¶
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