Merge pull request #990 from rlan35/rj_fork

Update vrf vdf and crosslink fields
pull/1007/head
Rongjian Lan 6 years ago committed by GitHub
commit cda425dfd1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      consensus/consensus_v2.go
  2. 14
      core/blockchain.go
  3. 2
      core/resharding.go
  4. 19
      core/types/block.go
  5. 3
      core/types/transaction.go
  6. 2
      drand/drand_leader.go
  7. 2
      node/node_handler.go

@ -822,7 +822,7 @@ func (consensus *Consensus) Start(blockChannel chan *types.Block, stopChan chan
// vrfBitmap.SetMask(bitmap)
//
// // TODO: check validity of pRnd
// newBlock.AddRandPreimage(pRnd)
// newBlock.AddVrf(pRnd)
//}
rnd, blockHash, err := consensus.GetNextRnd()
@ -830,7 +830,7 @@ func (consensus *Consensus) Start(blockChannel chan *types.Block, stopChan chan
// Verify the randomness
_ = blockHash
utils.GetLogger().Info("Adding randomness into new block", "rnd", rnd)
newBlock.AddRandSeed(rnd)
newBlock.AddVdf([258]byte{}) // TODO(HB): add real vdf
} else {
utils.GetLogger().Info("Failed to get randomness", "error", err)
}

@ -1703,22 +1703,24 @@ func (bc *BlockChain) WriteShardState(
return nil
}
// GetRandSeedByNumber retrieves the rand seed given the block number, return 0 if not exist
func (bc *BlockChain) GetRandSeedByNumber(number uint64) [32]byte {
// GetVdfByNumber retrieves the rand seed given the block number, return 0 if not exist
func (bc *BlockChain) GetVdfByNumber(number uint64) [32]byte {
header := bc.GetHeaderByNumber(number)
if header == nil {
return [32]byte{}
}
return header.RandSeed
result := [32]byte{}
copy(result[:], header.Vdf[:32])
return result
}
// GetRandPreimageByNumber retrieves the randomness preimage given the block number, return 0 if not exist
func (bc *BlockChain) GetRandPreimageByNumber(number uint64) [32]byte {
// GetVrfByNumber retrieves the randomness preimage given the block number, return 0 if not exist
func (bc *BlockChain) GetVrfByNumber(number uint64) [32]byte {
header := bc.GetHeaderByNumber(number)
if header == nil {
return [32]byte{}
}
return header.RandPreimage
return header.Vrf
}
// GetShardState returns the shard state for the given epoch,

@ -166,7 +166,7 @@ func GetShardingStateFromBlockChain(bc *BlockChain, epoch *big.Int) (*ShardingSt
shardState = shardState.DeepCopy()
blockNumber := GetBlockNumberFromEpoch(epoch.Uint64())
rndSeedBytes := bc.GetRandSeedByNumber(blockNumber)
rndSeedBytes := bc.GetVdfByNumber(blockNumber)
rndSeed := binary.BigEndian.Uint64(rndSeedBytes[:])
return &ShardingState{epoch: epoch.Uint64(), rnd: rndSeed, shardState: shardState, numShards: len(shardState)}, nil

@ -90,10 +90,13 @@ type Header struct {
PrepareBitmap []byte `json:"prepareBitmap" gencodec:"required"` // Contains which validator signed
CommitSignature [96]byte `json:"commitSignature" gencodec:"required"`
CommitBitmap []byte `json:"commitBitmap" gencodec:"required"` // Contains which validator signed
RandPreimage [32]byte `json:"randPreimage"`
RandSeed [32]byte `json:"randSeed"`
Vrf [32]byte `json:"vrf"`
VrfProof [96]byte `json:"vrfProof"`
Vdf [258]byte `json:"vdf"`
VdfProof [258]byte `json:"vdfProof"`
ShardStateHash common.Hash `json:"shardStateRoot"`
ShardState ShardState `json:"shardState"`
CrossLinks [][]byte `json:"crossLinks"`
}
// field type overrides for gencodec
@ -471,14 +474,14 @@ func Number(b1, b2 *Block) bool {
return b1.header.Number.Cmp(b2.header.Number) < 0
}
// AddRandSeed add random seed into block header
func (b *Block) AddRandSeed(randSeed [32]byte) {
b.header.RandSeed = randSeed
// AddVdf add vdf into block header
func (b *Block) AddVdf(vdf [258]byte) {
b.header.Vdf = vdf
}
// AddRandPreimage add randomness preimage into block header
func (b *Block) AddRandPreimage(pRnd [32]byte) {
b.header.RandPreimage = pRnd
// AddVrf add vrf into block header
func (b *Block) AddVrf(vrf [32]byte) {
b.header.Vrf = vrf
}
// AddShardState add shardState into block header

@ -50,6 +50,7 @@ type txdata struct {
Price *big.Int `json:"gasPrice" gencodec:"required"`
GasLimit uint64 `json:"gas" gencodec:"required"`
ShardID uint32 `json:"shardID" gencodec:"required"`
ToShardID uint32 `json:"toShardID" rlp:"nil"` // for cross-shard tx's destination shard ID; nil means intra-shard tx
Recipient *common.Address `json:"to" rlp:"nil"` // nil means contract creation
Amount *big.Int `json:"value" gencodec:"required"`
Payload []byte `json:"input" gencodec:"required"`
@ -235,7 +236,7 @@ func (tx *Transaction) Hash() common.Hash {
}
// Size returns the true RLP encoded storage size of the transaction, either by
// encoding and returning it, or returning a previsouly cached value.
// encoding and returning it, or returning a previously cached value.
func (tx *Transaction) Size() common.StorageSize {
if size := tx.size.Load(); size != nil {
return size.(common.StorageSize)

@ -33,7 +33,7 @@ func (dRand *DRand) WaitForEpochBlock(blockChannel chan *types.Block, stopChan c
if core.IsEpochLastBlock(newBlock) {
dRand.init(newBlock)
}
pRnd := newBlock.Header().RandPreimage
pRnd := newBlock.Header().Vrf
zeros := [32]byte{}
if core.IsEpochBlock(newBlock) && !bytes.Equal(pRnd[:], zeros[:]) {
// The epoch block should contain the randomness preimage pRnd

@ -262,7 +262,7 @@ func (node *Node) VerifyNewBlock(newBlock *types.Block) error {
}
// TODO: verify the vrf randomness
_ = newBlock.Header().RandPreimage
_ = newBlock.Header().Vrf
err = node.validateNewShardState(newBlock, &node.CurrentStakes)
if err != nil {

Loading…
Cancel
Save