Documentation ¶
Overview ¶
Package chain provides chain for chestnut.
Package chain provides chain for chestnut.
Package chain provides chain for chestnut.
Package chain provides chain for chestnut.
Package chain provides chain for chestnut.
Package chain provides chain for chestnut.
Package chain provides chain for chestnut.
Package chain provides chain for chestnut.
Package chain provides chain for chestnut.
Package chain provides chain for chestnut.
Package chain provides chain for chestnut.
Package chain provides chain for chestnut.
Package chain provides chain for chestnut.
Package chain provides chain for chestnut.
Index ¶
- Constants
- Variables
- func CreateBlock(oldBlock *chestnutpb.Block, trxs []*chestnutpb.Trx, groupPublicKey []byte, ...) (*chestnutpb.Block, error)
- func CreateGeneisBlock(groupId string, groupPublicKey p2pcrypto.PubKey) (*chestnutpb.Block, error)
- func GetAllTrxs(blocks []*chestnutpb.Block) ([]*chestnutpb.Trx, error)
- func GetMyTrxs(blockIds []string, nodename string, userSignPubkey string) ([]*chestnutpb.Trx, error)
- func GetTrimedBlocks(blocks []*chestnutpb.Block, nodename string) ([]string, error)
- func Hash(data []byte) []byte
- func IsBlockValid(newBlock, oldBlock *chestnutpb.Block) (bool, error)
- func RecalChainHeight(blocks []*chestnutpb.Block, currentHeight int64, ...) (int64, string, error)
- func UpdateResendCount(trxs []*chestnutpb.Trx) ([]*chestnutpb.Trx, error)
- type Chain
- func (chain *Chain) CreateConsensus()
- func (chain *Chain) GetProducerTrxMgr() *TrxMgr
- func (chain *Chain) GetUserTrxMgr() *TrxMgr
- func (chain *Chain) HandleBlock(block *chestnutpb.Block) error
- func (chain *Chain) HandleTrx(trx *chestnutpb.Trx) error
- func (chain *Chain) Init(group *Group) error
- func (chain *Chain) IsSyncerReady() bool
- func (chain *Chain) StartInitialSync(block *chestnutpb.Block) error
- func (chain *Chain) StopSync() error
- func (chain *Chain) SyncBackward(block *chestnutpb.Block) error
- func (chain *Chain) UpdChainInfo(height int64, blockId string) error
- func (chain *Chain) UpdProducerList()
- type ChainMolassesIface
- type Consensus
- type Group
- func (grp *Group) CreateGrp(item *chestnutpb.GroupItem) error
- func (grp *Group) DelGrp() error
- func (grp *Group) GetAnnouncedProducer() ([]*chestnutpb.AnnounceItem, error)
- func (grp *Group) GetAnnouncedUser() ([]*chestnutpb.AnnounceItem, error)
- func (grp *Group) GetBlock(blockId string) (*chestnutpb.Block, error)
- func (grp *Group) GetBlockedUser() ([]*chestnutpb.DenyUserItem, error)
- func (grp *Group) GetGroupCtn(filter string) ([]*chestnutpb.PostItem, error)
- func (grp *Group) GetProducers() ([]*chestnutpb.ProducerItem, error)
- func (grp *Group) GetTrx(trxId string) (*chestnutpb.Trx, error)
- func (grp *Group) Init(item *chestnutpb.GroupItem)
- func (grp *Group) IsProducerAnnounced(producerSignPubkey string) (bool, error)
- func (grp *Group) LeaveGrp() error
- func (grp *Group) PostToGroup(content proto.Message) (string, error)
- func (grp *Group) StartSync() error
- func (grp *Group) StopSync() error
- func (grp *Group) TearDown()
- func (grp *Group) UpdAnnounce(item *chestnutpb.AnnounceItem) (string, error)
- func (grp *Group) UpdBlkList(item *chestnutpb.DenyUserItem) (string, error)
- func (grp *Group) UpdProducer(item *chestnutpb.ProducerItem) (string, error)
- func (grp *Group) UpdSchema(item *chestnutpb.SchemaItem) (string, error)
- type GroupMgr
- type GroupProducer
- type Molasses
- type MolassesProducer
- func (producer *MolassesProducer) AddBlock(block *chestnutpb.Block) error
- func (producer *MolassesProducer) AddBlockToPool(block *chestnutpb.Block)
- func (producer *MolassesProducer) AddProducedBlock(trx *chestnutpb.Trx) error
- func (producer *MolassesProducer) AddTrx(trx *chestnutpb.Trx)
- func (producer *MolassesProducer) GetBlockBackward(trx *chestnutpb.Trx) error
- func (producer *MolassesProducer) GetBlockForward(trx *chestnutpb.Trx) error
- func (producer *MolassesProducer) Init(item *chestnutpb.GroupItem, nodename string, iface ChainMolassesIface)
- type MolassesUser
- func (user *MolassesUser) AddBlock(block *chestnutpb.Block) error
- func (user *MolassesUser) Init(item *chestnutpb.GroupItem, nodename string, cIface ChainMolassesIface)
- func (user *MolassesUser) PostToGroup(content proto.Message) (string, error)
- func (user *MolassesUser) UpdAnnounce(item *chestnutpb.AnnounceItem) (string, error)
- func (user *MolassesUser) UpdBlkList(item *chestnutpb.DenyUserItem) (string, error)
- func (user *MolassesUser) UpdProducer(item *chestnutpb.ProducerItem) (string, error)
- func (user *MolassesUser) UpdSchema(item *chestnutpb.SchemaItem) (string, error)
- type Producer
- type ProducerStatus
- type Syncer
- func (syncer *Syncer) AddBlockSynced(resp *chestnutpb.ReqBlockResp, block *chestnutpb.Block) error
- func (syncer *Syncer) ContinueSync(block *chestnutpb.Block) error
- func (syncer *Syncer) GetBlockToGenesis(blockid string, genesisblkid string) (string, error)
- func (syncer *Syncer) Init(grp *Group, trxMgr *TrxMgr)
- func (syncer *Syncer) ShowChainStruct()
- func (syncer *Syncer) StopSync() error
- func (syncer *Syncer) SyncBackward(block *chestnutpb.Block) error
- func (syncer *Syncer) SyncForward(block *chestnutpb.Block) error
- type TrxMgr
- func (trxMgr *TrxMgr) CreateTrx(msgType chestnutpb.TrxType, data []byte) (*chestnutpb.Trx, error)
- func (trxMgr *TrxMgr) CreateTrxWithoutSign(msgType chestnutpb.TrxType, data []byte) (*chestnutpb.Trx, []byte, error)
- func (trxMgr *TrxMgr) CustomSendTrx(trx *chestnutpb.Trx) error
- func (trxMgr *TrxMgr) Init(groupItem *chestnutpb.GroupItem, psconn pubsubconn.PubSubConn)
- func (trxMgr *TrxMgr) PostAny(content proto.Message) (string, error)
- func (trxMgr *TrxMgr) PostBytes(trxtype chestnutpb.TrxType, encodedcontent []byte) (string, error)
- func (trxMgr *TrxMgr) ResendTrx(trx *chestnutpb.Trx) error
- func (trxMgr *TrxMgr) SendAnnounceTrx(item *chestnutpb.AnnounceItem) (string, error)
- func (trxMgr *TrxMgr) SendBlock(blk *chestnutpb.Block) error
- func (trxMgr *TrxMgr) SendBlockProduced(blk *chestnutpb.Block) error
- func (trxMgr *TrxMgr) SendRegProducerTrx(item *chestnutpb.ProducerItem) (string, error)
- func (trxMgr *TrxMgr) SendReqBlockBackward(block *chestnutpb.Block) error
- func (trxMgr *TrxMgr) SendReqBlockForward(block *chestnutpb.Block) error
- func (trxMgr *TrxMgr) SendReqBlockResp(req *chestnutpb.ReqBlock, block *chestnutpb.Block, ...) error
- func (trxMgr *TrxMgr) SendUpdAuthTrx(item *chestnutpb.DenyUserItem) (string, error)
- func (trxMgr *TrxMgr) SendUpdSchemaTrx(item *chestnutpb.SchemaItem) (string, error)
- func (trxMgr *TrxMgr) SetNodeName(nodename string)
- func (trxMgr *TrxMgr) VerifyTrx(trx *chestnutpb.Trx) (bool, error)
- type User
Constants ¶
const ( USER_CHANNEL_PREFIX = "user_channel_" PRODUCER_CHANNEL_PREFIX = "prod_channel_" )
const ( SYNCING_FORWARD = 0 SYNCING_BACKWARD = 1 SYNC_FAILED = 2 IDLE = 3 )
const ( Hours = 0 Mins = 5 Sec = 0 )
const MERGE_TIMER time.Duration = 5
const OBJECT_SIZE_LIMIT = 200 * 1024 //(200Kb)
const PRODUCE_TIMER time.Duration = 5
const TRXS_TOTAL_SIZE int = 900 * 1024
Variables ¶
var RETRY_LIMIT = 30
var WAIT_BLOCK_TIME_S = 10
Functions ¶
func CreateBlock ¶
func CreateBlock(oldBlock *chestnutpb.Block, trxs []*chestnutpb.Trx, groupPublicKey []byte, opts ...string) (*chestnutpb.Block, error)
func CreateGeneisBlock ¶
func GetAllTrxs ¶
func GetAllTrxs(blocks []*chestnutpb.Block) ([]*chestnutpb.Trx, error)
get all trx from the block list
func GetMyTrxs ¶
func GetMyTrxs(blockIds []string, nodename string, userSignPubkey string) ([]*chestnutpb.Trx, error)
get all trx belongs to me from the block list
func GetTrimedBlocks ¶
func GetTrimedBlocks(blocks []*chestnutpb.Block, nodename string) ([]string, error)
from root of the new block tree, get all blocks trimed when not belong to longest path
func IsBlockValid ¶
func IsBlockValid(newBlock, oldBlock *chestnutpb.Block) (bool, error)
func RecalChainHeight ¶
func RecalChainHeight(blocks []*chestnutpb.Block, currentHeight int64, currentHighestBlock *chestnutpb.Block, nodename string) (int64, string, error)
find the highest block from the block tree
func UpdateResendCount ¶
func UpdateResendCount(trxs []*chestnutpb.Trx) ([]*chestnutpb.Trx, error)
update resend count (+1) for all trxs
Types ¶
type Chain ¶
type Chain struct { ProducerPool map[string]*chestnutpb.ProducerItem Syncer *Syncer Consensus Consensus // contains filtered or unexported fields }
func (*Chain) CreateConsensus ¶
func (chain *Chain) CreateConsensus()
func (*Chain) GetProducerTrxMgr ¶
func (*Chain) GetUserTrxMgr ¶
func (*Chain) HandleBlock ¶
func (chain *Chain) HandleBlock(block *chestnutpb.Block) error
func (*Chain) IsSyncerReady ¶
func (*Chain) StartInitialSync ¶
func (chain *Chain) StartInitialSync(block *chestnutpb.Block) error
func (*Chain) SyncBackward ¶
func (chain *Chain) SyncBackward(block *chestnutpb.Block) error
func (*Chain) UpdProducerList ¶
func (chain *Chain) UpdProducerList()
type ChainMolassesIface ¶
type Group ¶
type Group struct { // Group Item Item *chestnutpb.GroupItem ChainCtx *Chain }
func (*Group) GetAnnouncedProducer ¶
func (grp *Group) GetAnnouncedProducer() ([]*chestnutpb.AnnounceItem, error)
func (*Group) GetAnnouncedUser ¶
func (grp *Group) GetAnnouncedUser() ([]*chestnutpb.AnnounceItem, error)
func (*Group) GetBlockedUser ¶
func (grp *Group) GetBlockedUser() ([]*chestnutpb.DenyUserItem, error)
func (*Group) GetGroupCtn ¶
func (grp *Group) GetGroupCtn(filter string) ([]*chestnutpb.PostItem, error)
func (*Group) GetProducers ¶
func (grp *Group) GetProducers() ([]*chestnutpb.ProducerItem, error)
func (*Group) Init ¶
func (grp *Group) Init(item *chestnutpb.GroupItem)
func (*Group) IsProducerAnnounced ¶
func (*Group) UpdAnnounce ¶
func (grp *Group) UpdAnnounce(item *chestnutpb.AnnounceItem) (string, error)
func (*Group) UpdBlkList ¶
func (grp *Group) UpdBlkList(item *chestnutpb.DenyUserItem) (string, error)
func (*Group) UpdProducer ¶
func (grp *Group) UpdProducer(item *chestnutpb.ProducerItem) (string, error)
func (*Group) UpdSchema ¶
func (grp *Group) UpdSchema(item *chestnutpb.SchemaItem) (string, error)
type GroupMgr ¶
func GetGroupMgr ¶
func GetGroupMgr() *GroupMgr
func (*GroupMgr) GetGroupItem ¶
func (groupmgr *GroupMgr) GetGroupItem(groupId string) (*chestnutpb.GroupItem, error)
func (*GroupMgr) StopSyncAllGroup ¶
func (*GroupMgr) SyncAllGroup ¶
load and group add start syncing
type GroupProducer ¶
type Molasses ¶
type Molasses struct {
// contains filtered or unexported fields
}
func NewMolasses ¶
type MolassesProducer ¶
type MolassesProducer struct { ProduceTimer *time.Timer ProduceDone chan bool // contains filtered or unexported fields }
func (*MolassesProducer) AddBlock ¶
func (producer *MolassesProducer) AddBlock(block *chestnutpb.Block) error
addBlock for producer
func (*MolassesProducer) AddBlockToPool ¶
func (producer *MolassesProducer) AddBlockToPool(block *chestnutpb.Block)
func (*MolassesProducer) AddProducedBlock ¶
func (producer *MolassesProducer) AddProducedBlock(trx *chestnutpb.Trx) error
func (*MolassesProducer) AddTrx ¶
func (producer *MolassesProducer) AddTrx(trx *chestnutpb.Trx)
add trx to trx pool
func (*MolassesProducer) GetBlockBackward ¶
func (producer *MolassesProducer) GetBlockBackward(trx *chestnutpb.Trx) error
func (*MolassesProducer) GetBlockForward ¶
func (producer *MolassesProducer) GetBlockForward(trx *chestnutpb.Trx) error
func (*MolassesProducer) Init ¶
func (producer *MolassesProducer) Init(item *chestnutpb.GroupItem, nodename string, iface ChainMolassesIface)
type MolassesUser ¶
type MolassesUser struct {
// contains filtered or unexported fields
}
func (*MolassesUser) AddBlock ¶
func (user *MolassesUser) AddBlock(block *chestnutpb.Block) error
func (*MolassesUser) Init ¶
func (user *MolassesUser) Init(item *chestnutpb.GroupItem, nodename string, cIface ChainMolassesIface)
func (*MolassesUser) PostToGroup ¶
func (user *MolassesUser) PostToGroup(content proto.Message) (string, error)
func (*MolassesUser) UpdAnnounce ¶
func (user *MolassesUser) UpdAnnounce(item *chestnutpb.AnnounceItem) (string, error)
func (*MolassesUser) UpdBlkList ¶
func (user *MolassesUser) UpdBlkList(item *chestnutpb.DenyUserItem) (string, error)
func (*MolassesUser) UpdProducer ¶
func (user *MolassesUser) UpdProducer(item *chestnutpb.ProducerItem) (string, error)
func (*MolassesUser) UpdSchema ¶
func (user *MolassesUser) UpdSchema(item *chestnutpb.SchemaItem) (string, error)
type Producer ¶
type Producer interface { Init(item *chestnutpb.GroupItem, nodename string, iface ChainMolassesIface) AddTrx(trx *chestnutpb.Trx) AddBlockToPool(block *chestnutpb.Block) GetBlockForward(trx *chestnutpb.Trx) error GetBlockBackward(trx *chestnutpb.Trx) error AddProducedBlock(trx *chestnutpb.Trx) error AddBlock(block *chestnutpb.Block) error }
type ProducerStatus ¶
type ProducerStatus int
const ( StatusIdle ProducerStatus = iota StatusMerging StatusProducing )
type Syncer ¶
type Syncer struct { AskNextTimer *time.Timer AskNextTimeDone chan bool Status int8 // contains filtered or unexported fields }
func (*Syncer) AddBlockSynced ¶
func (syncer *Syncer) AddBlockSynced(resp *chestnutpb.ReqBlockResp, block *chestnutpb.Block) error
func (*Syncer) ContinueSync ¶
func (syncer *Syncer) ContinueSync(block *chestnutpb.Block) error
func (*Syncer) GetBlockToGenesis ¶
func (*Syncer) ShowChainStruct ¶
func (syncer *Syncer) ShowChainStruct()
func (*Syncer) SyncBackward ¶
func (syncer *Syncer) SyncBackward(block *chestnutpb.Block) error
Sync block "backward"
func (*Syncer) SyncForward ¶
func (syncer *Syncer) SyncForward(block *chestnutpb.Block) error
sync block "forward"
type TrxMgr ¶
type TrxMgr struct {
// contains filtered or unexported fields
}
func (*TrxMgr) CreateTrx ¶
func (trxMgr *TrxMgr) CreateTrx(msgType chestnutpb.TrxType, data []byte) (*chestnutpb.Trx, error)
func (*TrxMgr) CreateTrxWithoutSign ¶
func (trxMgr *TrxMgr) CreateTrxWithoutSign(msgType chestnutpb.TrxType, data []byte) (*chestnutpb.Trx, []byte, error)
func (*TrxMgr) CustomSendTrx ¶
func (trxMgr *TrxMgr) CustomSendTrx(trx *chestnutpb.Trx) error
func (*TrxMgr) Init ¶
func (trxMgr *TrxMgr) Init(groupItem *chestnutpb.GroupItem, psconn pubsubconn.PubSubConn)
func (*TrxMgr) SendAnnounceTrx ¶
func (trxMgr *TrxMgr) SendAnnounceTrx(item *chestnutpb.AnnounceItem) (string, error)
func (*TrxMgr) SendBlockProduced ¶
func (trxMgr *TrxMgr) SendBlockProduced(blk *chestnutpb.Block) error
func (*TrxMgr) SendRegProducerTrx ¶
func (trxMgr *TrxMgr) SendRegProducerTrx(item *chestnutpb.ProducerItem) (string, error)
func (*TrxMgr) SendReqBlockBackward ¶
func (trxMgr *TrxMgr) SendReqBlockBackward(block *chestnutpb.Block) error
func (*TrxMgr) SendReqBlockForward ¶
func (trxMgr *TrxMgr) SendReqBlockForward(block *chestnutpb.Block) error
func (*TrxMgr) SendReqBlockResp ¶
func (trxMgr *TrxMgr) SendReqBlockResp(req *chestnutpb.ReqBlock, block *chestnutpb.Block, result chestnutpb.ReqBlkResult) error
func (*TrxMgr) SendUpdAuthTrx ¶
func (trxMgr *TrxMgr) SendUpdAuthTrx(item *chestnutpb.DenyUserItem) (string, error)
func (*TrxMgr) SendUpdSchemaTrx ¶
func (trxMgr *TrxMgr) SendUpdSchemaTrx(item *chestnutpb.SchemaItem) (string, error)
func (*TrxMgr) SetNodeName ¶
type User ¶
type User interface { Init(item *chestnutpb.GroupItem, nodename string, iface ChainMolassesIface) UpdAnnounce(item *chestnutpb.AnnounceItem) (string, error) UpdBlkList(item *chestnutpb.DenyUserItem) (string, error) UpdSchema(item *chestnutpb.SchemaItem) (string, error) UpdProducer(item *chestnutpb.ProducerItem) (string, error) PostToGroup(content proto.Message) (string, error) AddBlock(block *chestnutpb.Block) error }