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"` Size hexutil.Uint64 `json:"size"`
GasLimit hexutil.Uint64 `json:"gasLimit"` GasLimit hexutil.Uint64 `json:"gasLimit"`
GasUsed hexutil.Uint64 `json:"gasUsed"` GasUsed hexutil.Uint64 `json:"gasUsed"`
VRF common.Hash `json:"vrf"`
VRFProof hexutil.Bytes `json:"vrfProof"`
Timestamp hexutil.Uint64 `json:"timestamp"` Timestamp hexutil.Uint64 `json:"timestamp"`
TransactionsRoot common.Hash `json:"transactionsRoot"` TransactionsRoot common.Hash `json:"transactionsRoot"`
ReceiptsRoot common.Hash `json:"receiptsRoot"` 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 { func newBlock(b *types.Block, leader common.Address) *Block {
head := b.Header() 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{ return &Block{
Number: (*hexutil.Big)(head.Number()), Number: (*hexutil.Big)(head.Number()),
Hash: b.Hash(), Hash: b.Hash(),
@ -188,6 +197,8 @@ func newBlock(b *types.Block, leader common.Address) *Block {
Size: hexutil.Uint64(b.Size()), Size: hexutil.Uint64(b.Size()),
GasLimit: hexutil.Uint64(head.GasLimit()), GasLimit: hexutil.Uint64(head.GasLimit()),
GasUsed: hexutil.Uint64(head.GasUsed()), GasUsed: hexutil.Uint64(head.GasUsed()),
VRF: vrf,
VRFProof: vrfProof,
Timestamp: hexutil.Uint64(head.Time().Uint64()), Timestamp: hexutil.Uint64(head.Time().Uint64()),
TransactionsRoot: head.TxHash(), TransactionsRoot: head.TxHash(),
ReceiptsRoot: head.ReceiptHash(), ReceiptsRoot: head.ReceiptHash(),

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

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

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

Loading…
Cancel
Save