Documentation
¶
Index ¶
- Variables
- func BlockToByteWithSig(block Block) []byte
- func BlockToByteWithoutSig(block Block) []byte
- func ComputeHashForBlock(blockBytes []byte) []byte
- func DownloadIPFS(address string) []byte
- func Int64ToBytes(i int64) []byte
- func LocalTxHash(tx LocalTransaction) string
- func LocalTxToByte(tx LocalTransaction) []byte
- func Random(low int, high int) int
- func RandomArray(length int, low int, high int) []int
- func SaveBlock(node_id int, block Block)
- func TxToByte(tx Transaction) []byte
- func TxToByteWithoutDeltas(tx Transaction) []byte
- func UploadIPFS(data []byte) string
- func ValidCandidateBlock(lastBlock Block, candidateBlock Block, globalParam [][]float64, ...) bool
- func ValidChain(localChain []Block, peerChain []Block) bool
- func ValidLocalTx(tx LocalTransaction, modelSize []int) bool
- func ValidVerifiedBlock(lastBlock Block, verifiedBlock Block) bool
- type Block
- type Blockchain
- type Global
- type LocalTransaction
- type Member
- type MemberSet
- type Peer
- type PeerSet
- type Signature
- type Transaction
- type TransactionPool
Constants ¶
This section is empty.
Variables ¶
View Source
var ( CommitteeSize = 15 //5,10,15,20 NumTxs = 50 // the maximum number of transactions that contained in the pool BaseNode = ":9000" // the initial node in the blockchain network DefaultStake = 1 NodeNum = 100 //100, 200, 500, 1000 SybilRatio = 0.0 //the fraction of sybils in blockchain nodes MaxVoteStep = 5 BlockTimeout = 240 * time.Second VotingTimeout = 200 * time.Second CommiteeSleep = 20 * time.Second CandidateSleep = 20 * time.Second )
Functions ¶
func BlockToByteWithSig ¶
func BlockToByteWithoutSig ¶
func ComputeHashForBlock ¶
func DownloadIPFS ¶
func Int64ToBytes ¶
func LocalTxHash ¶
func LocalTxHash(tx LocalTransaction) string
func LocalTxToByte ¶
func LocalTxToByte(tx LocalTransaction) []byte
func TxToByte ¶
func TxToByte(tx Transaction) []byte
func TxToByteWithoutDeltas ¶
func TxToByteWithoutDeltas(tx Transaction) []byte
func UploadIPFS ¶
func ValidCandidateBlock ¶
func ValidChain ¶
func ValidLocalTx ¶
func ValidLocalTx(tx LocalTransaction, modelSize []int) bool
func ValidVerifiedBlock ¶
Types ¶
type Block ¶
type Block struct {
Index int64 `json:"index"` // the index of current block
TimeStamp int64 `json:"timeStamp"` // the creation timestamp
PrevBlockHash string `json:"prevHash"` // the previous block hash
Transactions []Transaction `json:"transactions"` // transactions contained in the block
Signatures []Signature `json:"signatures"`
}
func CreateBlock ¶
func CreateBlock(lastBlock Block, txs []Transaction) Block
type Blockchain ¶
type Blockchain struct {
Chain []Block `json:"chain"` // linear chain structure
Transactions TransactionPool `json:"transactions"` // the transactions
Nodes PeerSet `json:"nodes"` // the participated nodes
Committee MemberSet `json:"committee"` // the committee members
}
func NewBlockchain ¶
func NewBlockchain() *Blockchain
func (*Blockchain) AddBlock ¶
func (bc *Blockchain) AddBlock(block Block, id int)
Add block to the chain
func (*Blockchain) AddTransaction ¶
func (bc *Blockchain) AddTransaction(tx LocalTransaction)
Receive transaction and put it into the local transaction pool
func (*Blockchain) CommitteeClear ¶
func (bc *Blockchain) CommitteeClear()
Clear the committee group, called when a new block is generated and wait for the next round committee construction
func (*Blockchain) CommitteeUpdate ¶
func (bc *Blockchain) CommitteeUpdate(member Member) bool
Update the committee group, called when the proof of role is valid
func (*Blockchain) GetLength ¶
func (bc *Blockchain) GetLength() int
Get the length of the chain Returns: -{int} length
func (*Blockchain) LastBlock ¶
func (bc *Blockchain) LastBlock() Block
type LocalTransaction ¶
type MemberSet ¶
func NewMemberSet ¶
func NewMemberSet() MemberSet
type PeerSet ¶
func NewPeerSet ¶
func NewPeerSet() PeerSet
type Transaction ¶
type Transaction struct {
Task string `json:"task"`
Round int `json:"round"`
GlobalModel string `json:"globalModel"` //the IPFS address of the global model
GlobalModelSig Signature `json:"SenderSignauture"` //the signature of uploaded global
Deltas []LocalTransaction `json:"modelUpdates"` //the deltas will be removed when the confirmed block generated
}
Custom transaction
func CreateTx_Malicious ¶
type TransactionPool ¶
type TransactionPool struct {
Transactions map[string]LocalTransaction
// contains filtered or unexported fields
}
func NewTxPool ¶
func NewTxPool() TransactionPool
func (*TransactionPool) Add ¶
func (txp *TransactionPool) Add(tx LocalTransaction) bool
func (*TransactionPool) Keys ¶
func (txp *TransactionPool) Keys() []string
Click to show internal directories.
Click to hide internal directories.