chain

package
v0.0.0-...-6b2b62e Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2022 License: GPL-3.0 Imports: 18 Imported by: 0

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

View Source
const (
	USER_CHANNEL_PREFIX     = "user_channel_"
	PRODUCER_CHANNEL_PREFIX = "prod_channel_"
)
View Source
const (
	SYNCING_FORWARD  = 0
	SYNCING_BACKWARD = 1
	SYNC_FAILED      = 2
	IDLE             = 3
)
View Source
const (
	Hours = 0
	Mins  = 5
	Sec   = 0
)
View Source
const MERGE_TIMER time.Duration = 5
View Source
const OBJECT_SIZE_LIMIT = 200 * 1024 //(200Kb)
View Source
const PRODUCE_TIMER time.Duration = 5
View Source
const TRXS_TOTAL_SIZE int = 900 * 1024

Variables

View Source
var RETRY_LIMIT = 30
View Source
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 CreateGeneisBlock(groupId string, groupPublicKey p2pcrypto.PubKey) (*chestnutpb.Block, error)

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 Hash

func Hash(data []byte) []byte

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 *Chain) GetProducerTrxMgr() *TrxMgr

func (*Chain) GetUserTrxMgr

func (chain *Chain) GetUserTrxMgr() *TrxMgr

func (*Chain) HandleBlock

func (chain *Chain) HandleBlock(block *chestnutpb.Block) error

func (*Chain) HandleTrx

func (chain *Chain) HandleTrx(trx *chestnutpb.Trx) error

func (*Chain) Init

func (chain *Chain) Init(group *Group) error

func (*Chain) IsSyncerReady

func (chain *Chain) IsSyncerReady() bool

func (*Chain) StartInitialSync

func (chain *Chain) StartInitialSync(block *chestnutpb.Block) error

func (*Chain) StopSync

func (chain *Chain) StopSync() error

func (*Chain) SyncBackward

func (chain *Chain) SyncBackward(block *chestnutpb.Block) error

func (*Chain) UpdChainInfo

func (chain *Chain) UpdChainInfo(height int64, blockId string) error

func (*Chain) UpdProducerList

func (chain *Chain) UpdProducerList()

type ChainMolassesIface

type ChainMolassesIface interface {
	GetUserTrxMgr() *TrxMgr
	GetProducerTrxMgr() *TrxMgr
	UpdChainInfo(height int64, blockId string) error
	UpdProducerList()
	CreateConsensus()
	IsSyncerReady() bool
	SyncBackward(block *chestnutpb.Block) error
}

type Consensus

type Consensus interface {
	Name() string
	Producer() Producer
	User() User
}

type Group

type Group struct {
	// Group Item
	Item     *chestnutpb.GroupItem
	ChainCtx *Chain
}

func (*Group) CreateGrp

func (grp *Group) CreateGrp(item *chestnutpb.GroupItem) error

func (*Group) DelGrp

func (grp *Group) DelGrp() error

func (*Group) GetAnnouncedProducer

func (grp *Group) GetAnnouncedProducer() ([]*chestnutpb.AnnounceItem, error)

func (*Group) GetAnnouncedUser

func (grp *Group) GetAnnouncedUser() ([]*chestnutpb.AnnounceItem, error)

func (*Group) GetBlock

func (grp *Group) GetBlock(blockId string) (*chestnutpb.Block, 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) GetTrx

func (grp *Group) GetTrx(trxId string) (*chestnutpb.Trx, error)

func (*Group) Init

func (grp *Group) Init(item *chestnutpb.GroupItem)

func (*Group) IsProducerAnnounced

func (grp *Group) IsProducerAnnounced(producerSignPubkey string) (bool, error)

func (*Group) LeaveGrp

func (grp *Group) LeaveGrp() error

func (*Group) PostToGroup

func (grp *Group) PostToGroup(content proto.Message) (string, error)

func (*Group) StartSync

func (grp *Group) StartSync() error

func (*Group) StopSync

func (grp *Group) StopSync() error

func (*Group) TearDown

func (grp *Group) TearDown()

teardown group

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

type GroupMgr struct {
	Groups map[string]*Group
	// contains filtered or unexported fields
}

func GetGroupMgr

func GetGroupMgr() *GroupMgr

func InitGroupMgr

func InitGroupMgr(dbMgr *storage.DbMgr) *GroupMgr

TODO:singlaton

func (*GroupMgr) GetGroupItem

func (groupmgr *GroupMgr) GetGroupItem(groupId string) (*chestnutpb.GroupItem, error)

func (*GroupMgr) Release

func (groupmgr *GroupMgr) Release()

func (*GroupMgr) StopSyncAllGroup

func (groupmgr *GroupMgr) StopSyncAllGroup() error

func (*GroupMgr) SyncAllGroup

func (groupmgr *GroupMgr) SyncAllGroup() error

load and group add start syncing

type GroupProducer

type GroupProducer struct {
	ProducerPubkey   string
	ProducerPriority int8
}

type Molasses

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

func NewMolasses

func NewMolasses(p Producer, u User) *Molasses

func (*Molasses) Name

func (m *Molasses) Name() string

func (*Molasses) Producer

func (m *Molasses) Producer() Producer

func (*Molasses) User

func (m *Molasses) User() User

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 *Syncer) GetBlockToGenesis(blockid string, genesisblkid string) (string, error)

func (*Syncer) Init

func (syncer *Syncer) Init(grp *Group, trxMgr *TrxMgr)

func (*Syncer) ShowChainStruct

func (syncer *Syncer) ShowChainStruct()

func (*Syncer) StopSync

func (syncer *Syncer) StopSync() error

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) PostAny

func (trxMgr *TrxMgr) PostAny(content proto.Message) (string, error)

func (*TrxMgr) PostBytes

func (trxMgr *TrxMgr) PostBytes(trxtype chestnutpb.TrxType, encodedcontent []byte) (string, error)

func (*TrxMgr) ResendTrx

func (trxMgr *TrxMgr) ResendTrx(trx *chestnutpb.Trx) error

func (*TrxMgr) SendAnnounceTrx

func (trxMgr *TrxMgr) SendAnnounceTrx(item *chestnutpb.AnnounceItem) (string, error)

func (*TrxMgr) SendBlock

func (trxMgr *TrxMgr) SendBlock(blk *chestnutpb.Block) 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

func (trxMgr *TrxMgr) SetNodeName(nodename string)

func (*TrxMgr) VerifyTrx

func (trxMgr *TrxMgr) VerifyTrx(trx *chestnutpb.Trx) (bool, error)

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
}

Jump to

Keyboard shortcuts

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