Add vrf and proof in header and block rpc (#3820)

* Add vrf and proof in header and block rpc

* Add vrf and proof to rpc v2 and eth rpc
pull/3825/head
Rongjian Lan 3 years ago committed by GitHub
parent b21faa4227
commit 8c8675b25e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      rpc/eth/types.go
  2. 11
      rpc/types.go
  3. 24
      rpc/v1/types.go
  4. 24
      rpc/v2/types.go

@ -29,6 +29,8 @@ type Block struct {
Size hexutil.Uint64 `json:"size"`
GasLimit hexutil.Uint64 `json:"gasLimit"`
GasUsed hexutil.Uint64 `json:"gasUsed"`
VRF common.Hash `json:"vrf"`
VRFProof hexutil.Bytes `json:"vrfProof"`
Timestamp hexutil.Uint64 `json:"timestamp"`
TransactionsRoot common.Hash `json:"transactionsRoot"`
ReceiptsRoot common.Hash `json:"receiptsRoot"`
@ -173,6 +175,13 @@ func NewBlock(b *types.Block, blockArgs *rpc_common.BlockArgs, leaderAddress str
func newBlock(b *types.Block, leader common.Address) *Block {
head := b.Header()
vrfAndProof := head.Vrf()
vrf := common.Hash{}
vrfProof := []byte{}
if len(vrfAndProof) == 32+96 {
copy(vrf[:], vrfAndProof[:32])
vrfProof = vrfAndProof[32:]
}
return &Block{
Number: (*hexutil.Big)(head.Number()),
Hash: b.Hash(),
@ -188,6 +197,8 @@ func newBlock(b *types.Block, leader common.Address) *Block {
Size: hexutil.Uint64(b.Size()),
GasLimit: hexutil.Uint64(head.GasLimit()),
GasUsed: hexutil.Uint64(head.GasUsed()),
VRF: vrf,
VRFProof: vrfProof,
Timestamp: hexutil.Uint64(head.Time().Uint64()),
TransactionsRoot: head.TxHash(),
ReceiptsRoot: head.ReceiptHash(),

@ -214,6 +214,8 @@ type HeaderInformation struct {
UnixTime uint64 `json:"unixtime"`
LastCommitSig string `json:"lastCommitSig"`
LastCommitBitmap string `json:"lastCommitBitmap"`
VRF string `json:"vrf"`
VRFProof string `json:"vrfProof"`
CrossLinks *types.CrossLinks `json:"crossLinks,omitempty"`
}
@ -223,6 +225,13 @@ func NewHeaderInformation(header *block.Header, leader string) *HeaderInformatio
return nil
}
vrfAndProof := header.Vrf()
vrf := common.Hash{}
vrfProof := []byte{}
if len(vrfAndProof) == 32+96 {
copy(vrf[:], vrfAndProof[:32])
vrfProof = vrfAndProof[32:]
}
result := &HeaderInformation{
BlockHash: header.Hash(),
BlockNumber: header.Number().Uint64(),
@ -233,6 +242,8 @@ func NewHeaderInformation(header *block.Header, leader string) *HeaderInformatio
UnixTime: header.Time().Uint64(),
Timestamp: time.Unix(header.Time().Int64(), 0).UTC().String(),
LastCommitBitmap: hex.EncodeToString(header.LastCommitBitmap()),
VRF: hex.EncodeToString(vrf[:]),
VRFProof: hex.EncodeToString(vrfProof),
}
sig := header.LastCommitSignature()

@ -33,6 +33,8 @@ type BlockWithTxHash struct {
Size hexutil.Uint64 `json:"size"`
GasLimit hexutil.Uint64 `json:"gasLimit"`
GasUsed hexutil.Uint64 `json:"gasUsed"`
VRF common.Hash `json:"vrf"`
VRFProof hexutil.Bytes `json:"vrfProof"`
Timestamp hexutil.Uint64 `json:"timestamp"`
TransactionsRoot common.Hash `json:"transactionsRoot"`
ReceiptsRoot common.Hash `json:"receiptsRoot"`
@ -61,6 +63,8 @@ type BlockWithFullTx struct {
Size hexutil.Uint64 `json:"size"`
GasLimit hexutil.Uint64 `json:"gasLimit"`
GasUsed hexutil.Uint64 `json:"gasUsed"`
VRF common.Hash `json:"vrf"`
VRFProof hexutil.Bytes `json:"vrfProof"`
Timestamp hexutil.Uint64 `json:"timestamp"`
TransactionsRoot common.Hash `json:"transactionsRoot"`
ReceiptsRoot common.Hash `json:"receiptsRoot"`
@ -588,6 +592,14 @@ func NewBlockWithTxHash(
}
head := b.Header()
vrfAndProof := head.Vrf()
vrf := common.Hash{}
vrfProof := []byte{}
if len(vrfAndProof) == 32+96 {
copy(vrf[:], vrfAndProof[:32])
vrfProof = vrfAndProof[32:]
}
blk := &BlockWithTxHash{
Number: (*hexutil.Big)(head.Number()),
ViewID: (*hexutil.Big)(head.ViewID()),
@ -604,6 +616,8 @@ func NewBlockWithTxHash(
Size: hexutil.Uint64(b.Size()),
GasLimit: hexutil.Uint64(head.GasLimit()),
GasUsed: hexutil.Uint64(head.GasUsed()),
VRF: vrf,
VRFProof: vrfProof,
Timestamp: hexutil.Uint64(head.Time().Uint64()),
TransactionsRoot: head.TxHash(),
ReceiptsRoot: head.ReceiptHash(),
@ -639,6 +653,14 @@ func NewBlockWithFullTx(
}
head := b.Header()
vrfAndProof := head.Vrf()
vrf := common.Hash{}
vrfProof := []byte{}
if len(vrfAndProof) == 32+96 {
copy(vrf[:], vrfAndProof[:32])
vrfProof = vrfAndProof[32:]
}
blk := &BlockWithFullTx{
Number: (*hexutil.Big)(head.Number()),
ViewID: (*hexutil.Big)(head.ViewID()),
@ -655,6 +677,8 @@ func NewBlockWithFullTx(
Size: hexutil.Uint64(b.Size()),
GasLimit: hexutil.Uint64(head.GasLimit()),
GasUsed: hexutil.Uint64(head.GasUsed()),
VRF: vrf,
VRFProof: vrfProof,
Timestamp: hexutil.Uint64(head.Time().Uint64()),
TransactionsRoot: head.TxHash(),
ReceiptsRoot: head.ReceiptHash(),

@ -35,6 +35,8 @@ type BlockWithTxHash struct {
Size uint64 `json:"size"`
GasLimit uint64 `json:"gasLimit"`
GasUsed uint64 `json:"gasUsed"`
VRF common.Hash `json:"vrf"`
VRFProof hexutil.Bytes `json:"vrfProof"`
Timestamp *big.Int `json:"timestamp"`
TransactionsRoot common.Hash `json:"transactionsRoot"`
ReceiptsRoot common.Hash `json:"receiptsRoot"`
@ -63,6 +65,8 @@ type BlockWithFullTx struct {
Size uint64 `json:"size"`
GasLimit uint64 `json:"gasLimit"`
GasUsed uint64 `json:"gasUsed"`
VRF common.Hash `json:"vrf"`
VRFProof hexutil.Bytes `json:"vrfProof"`
Timestamp *big.Int `json:"timestamp"`
TransactionsRoot common.Hash `json:"transactionsRoot"`
ReceiptsRoot common.Hash `json:"receiptsRoot"`
@ -604,6 +608,14 @@ func NewBlockWithTxHash(
}
head := b.Header()
vrfAndProof := head.Vrf()
vrf := common.Hash{}
vrfProof := []byte{}
if len(vrfAndProof) == 32+96 {
copy(vrf[:], vrfAndProof[:32])
vrfProof = vrfAndProof[32:]
}
blk := &BlockWithTxHash{
Number: head.Number(),
ViewID: head.ViewID(),
@ -620,6 +632,8 @@ func NewBlockWithTxHash(
Size: uint64(b.Size()),
GasLimit: head.GasLimit(),
GasUsed: head.GasUsed(),
VRF: vrf,
VRFProof: vrfProof,
Timestamp: head.Time(),
TransactionsRoot: head.TxHash(),
ReceiptsRoot: head.ReceiptHash(),
@ -655,6 +669,14 @@ func NewBlockWithFullTx(
}
head := b.Header()
vrfAndProof := head.Vrf()
vrf := common.Hash{}
vrfProof := []byte{}
if len(vrfAndProof) == 32+96 {
copy(vrf[:], vrfAndProof[:32])
vrfProof = vrfAndProof[32:]
}
blk := &BlockWithFullTx{
Number: head.Number(),
ViewID: head.ViewID(),
@ -671,6 +693,8 @@ func NewBlockWithFullTx(
Size: uint64(b.Size()),
GasLimit: head.GasLimit(),
GasUsed: head.GasUsed(),
VRF: vrf,
VRFProof: vrfProof,
Timestamp: head.Time(),
TransactionsRoot: head.TxHash(),
ReceiptsRoot: head.ReceiptHash(),

Loading…
Cancel
Save