Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement parachain inherents #2566

Merged
merged 125 commits into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from 122 commits
Commits
Show all changes
125 commits
Select commit Hold shift + click to select a range
ac5e507
temp
kishansagathiya May 20, 2022
2115a15
Implement Parachain Inherents
kishansagathiya May 23, 2022
298a2bd
clean up:
kishansagathiya May 23, 2022
02a931b
filling up more structs
kishansagathiya May 24, 2022
a0f8c1e
filling more structs
kishansagathiya May 24, 2022
d833b8b
more structs
kishansagathiya May 25, 2022
b11b9cf
fix lint
kishansagathiya May 25, 2022
2d48c7d
addressing some reviews
kishansagathiya May 30, 2022
5abb342
converted enums to VaryingDataType
kishansagathiya Jun 1, 2022
f548252
Update lib/runtime/wasmer/imports.go
kishansagathiya Jun 1, 2022
944ba17
Update lib/runtime/wasmer/imports.go
kishansagathiya Jun 1, 2022
e2d01c3
Update lib/runtime/wasmer/imports.go
kishansagathiya Jun 1, 2022
2973d33
Update lib/runtime/wasmer/imports.go
kishansagathiya Jun 1, 2022
6fd9518
Update lib/runtime/wasmer/imports.go
kishansagathiya Jun 1, 2022
3ecf9b1
Update lib/babe/parachain_inherents.go
kishansagathiya Jun 6, 2022
781d462
Update lib/babe/parachain_inherents.go
kishansagathiya Jun 6, 2022
d7e716b
addressed some of the reviews
kishansagathiya Jun 7, 2022
d1cb494
Merge branch 'kishan/feat/parachain-inherents' of github.com:ChainSaf…
kishansagathiya Jun 7, 2022
e16faaf
some parachain inherent tests
kishansagathiya Jun 14, 2022
37a7c1d
more tests
kishansagathiya Jun 15, 2022
bad42ee
wip decode functionality
timwu20 Jun 16, 2022
123fbbe
wip encode custom vdt
timwu20 Jun 16, 2022
f46408c
refactor tests
timwu20 Jun 16, 2022
f5d0810
more tests, fix decode for nested vdt
timwu20 Jun 17, 2022
9e8ef6a
update readme, provide example of nested VDTs
timwu20 Jun 17, 2022
24977ea
add copyright
timwu20 Jun 17, 2022
4a4be32
fix lint
timwu20 Jun 17, 2022
034efdb
Merge branch 'tim/custom-vdt' of github.com:ChainSafe/gossamer into k…
kishansagathiya Jun 23, 2022
cdb5b71
temp
kishansagathiya Jun 27, 2022
7cd88b3
Fixed tests
kishansagathiya Jun 27, 2022
e3e1347
fix lint
kishansagathiya Jun 27, 2022
fc92757
little more changes
kishansagathiya Jun 28, 2022
74c8d2b
Merge branch 'development' into kishan/feat/parachain-inherents
kishansagathiya Jun 28, 2022
6d7c387
fix lint
kishansagathiya Jun 28, 2022
40eb6fc
more fix up
kishansagathiya Jun 28, 2022
8a0c07b
make license
kishansagathiya Jul 4, 2022
f0f0522
Merge branch 'development' into kishan/feat/parachain-inherents
kishansagathiya Jul 4, 2022
9522517
some more changes
kishansagathiya Jul 4, 2022
8b96d4f
more changes
kishansagathiya Jul 4, 2022
41b4ac9
Merge branch 'development' into kishan/feat/parachain-inherents
kishansagathiya Jul 5, 2022
bc09949
update genesis file with latest runtime
kishansagathiya Jul 6, 2022
914374e
Revert "update genesis file with latest runtime"
kishansagathiya Jul 6, 2022
fbd59c5
modify genesis files with latest runtime
kishansagathiya Jul 6, 2022
e88438c
Merge branch 'development' into kishan/feat/parachain-inherents
kishansagathiya Jul 11, 2022
bf2fe8a
Merge branch 'development' into kishan/feat/parachain-inherents
kishansagathiya Jul 11, 2022
98b0356
temp
kishansagathiya Jul 12, 2022
c616756
modified genesis files
kishansagathiya Jul 13, 2022
937a05d
reverting genesis
kishansagathiya Jul 13, 2022
4f22128
more genesis changes
kishansagathiya Jul 13, 2022
3b5d06f
Merge branch 'development' into kishan/feat/parachain-inherents
kishansagathiya Aug 29, 2022
99c1c0c
test scaled encoding of parachain inherents
kishansagathiya Aug 31, 2022
02981ba
test scaled encoding of inherents
kishansagathiya Sep 6, 2022
bc4601d
add parent header in parachain inherent data
kishansagathiya Sep 9, 2022
90e81be
fix lint
kishansagathiya Sep 9, 2022
a1f2b3e
reverting uncessary change
kishansagathiya Sep 9, 2022
66503a6
Merge branch 'development' into kishan/feat/parachain-inherents
kishansagathiya Sep 9, 2022
afc80f3
Update dot/types/inherents.go
kishansagathiya Sep 16, 2022
c0d9f9f
Update lib/babe/build.go
kishansagathiya Sep 16, 2022
9c2900e
Update lib/babe/parachain_inherents.go
kishansagathiya Sep 16, 2022
74405cb
Update lib/babe/parachain_inherents_test.go
kishansagathiya Sep 16, 2022
ae1617e
Update dot/types/inherents.go
kishansagathiya Sep 16, 2022
9452425
Update lib/babe/build.go
kishansagathiya Sep 16, 2022
6fb11f6
Update lib/babe/parachain_inherents_test.go
kishansagathiya Sep 16, 2022
1407220
addressed some comments
kishansagathiya Sep 16, 2022
775aec1
addressed some reviews
kishansagathiya Sep 16, 2022
ec3f3d8
Update lib/babe/parachain_inherents.go
kishansagathiya Sep 16, 2022
9d0bd03
Update lib/babe/parachain_inherents.go
kishansagathiya Sep 16, 2022
0c48685
Update lib/babe/parachain_inherents.go
kishansagathiya Sep 16, 2022
c7f4c46
Update lib/babe/parachain_inherents.go
kishansagathiya Sep 16, 2022
a3d196e
Update lib/babe/parachain_inherents.go
kishansagathiya Sep 16, 2022
ba6a995
addressed some of the review
kishansagathiya Sep 16, 2022
0d590fe
Merge branch 'kishan/feat/parachain-inherents' of github.com:ChainSaf…
kishansagathiya Sep 16, 2022
895ac4d
addressed some reviews
kishansagathiya Sep 19, 2022
8ea0ddc
Update lib/babe/parachain_inherents_test.go
kishansagathiya Sep 19, 2022
44fef33
addressed more changes
kishansagathiya Sep 19, 2022
ca11b5d
Merge branch 'kishan/feat/parachain-inherents' of github.com:ChainSaf…
kishansagathiya Sep 19, 2022
99aa387
more reviews
kishansagathiya Sep 19, 2022
dbfb390
Merge branch 'development' into kishan/feat/parachain-inherents
kishansagathiya Sep 19, 2022
9474c83
fix lint
kishansagathiya Sep 19, 2022
7ccabb8
Merge branch 'development' into kishan/feat/parachain-inherents
kishansagathiya Sep 20, 2022
476c1d6
try
kishansagathiya Sep 20, 2022
7fbef75
removed phantom data comment
kishansagathiya Sep 20, 2022
b6fcb7c
Merge branch 'development' into kishan/feat/parachain-inherents
kishansagathiya Sep 20, 2022
eec8635
more reviews
kishansagathiya Sep 20, 2022
941c704
Update lib/babe/parachain_inherents.go
kishansagathiya Sep 21, 2022
d1a8bf5
Update lib/babe/parachain_inherents.go
kishansagathiya Sep 21, 2022
1b6bb12
Update lib/babe/parachain_inherents.go
kishansagathiya Sep 21, 2022
b46cb1e
some review addressed
kishansagathiya Sep 21, 2022
37e0441
Merge branch 'kishan/feat/parachain-inherents' of github.com:ChainSaf…
kishansagathiya Sep 21, 2022
ffe8bac
Merge branch 'development' into kishan/feat/parachain-inherents
kishansagathiya Sep 21, 2022
7b91a7d
revise SetStructInherent and SetInt64Inherent to generic SetInherent,…
timwu20 Sep 21, 2022
6d5ddaa
suppressing deepsource warnings
kishansagathiya Sep 22, 2022
116c52f
skip-cq to skipcq
kishansagathiya Sep 22, 2022
3fc10d8
Merge branch 'development' into kishan/feat/parachain-inherents
kishansagathiya Sep 22, 2022
9a6ea91
Merge branch 'development' into kishan/feat/parachain-inherents
kishansagathiya Sep 27, 2022
d7707aa
inherent improvements (#2815)
kishansagathiya Sep 27, 2022
0082def
Merge branch 'tim/kishan/feat/parachain-inherents' of github.com:Chai…
kishansagathiya Sep 28, 2022
bcbf177
Merge branch 'development' into kishan/feat/parachain-inherents
kishansagathiya Sep 28, 2022
ba71cdd
add copyright
kishansagathiya Sep 28, 2022
e032467
some fixes
kishansagathiya Sep 28, 2022
4657d9f
Update lib/babe/build.go
kishansagathiya Sep 28, 2022
b139ec0
Update dot/types/inherents.go
kishansagathiya Sep 28, 2022
693adbb
Update lib/babe/build.go
kishansagathiya Sep 28, 2022
6484640
Update lib/babe/parachain_inherents_test.go
kishansagathiya Sep 28, 2022
8d82ec5
Update lib/babe/parachain_inherents_test.go
kishansagathiya Sep 28, 2022
3815c0e
Update lib/babe/parachain_inherents.go
kishansagathiya Sep 28, 2022
5e927ec
use MapRange to preserve order of keys in map while encoding
kishansagathiya Sep 28, 2022
ba45f8f
Merge branch 'kishan/feat/parachain-inherents' of github.com:ChainSaf…
kishansagathiya Sep 28, 2022
f9f2740
Merge branch 'development' into kishan/feat/parachain-inherents
kishansagathiya Sep 29, 2022
62ca950
fix test
kishansagathiya Sep 29, 2022
942429e
Update lib/babe/parachain_inherents_test.go
kishansagathiya Sep 29, 2022
f4f5716
Update lib/babe/parachain_inherents_test.go
kishansagathiya Sep 29, 2022
4a697d0
Update lib/babe/parachain_inherents_test.go
kishansagathiya Sep 29, 2022
b658c9e
added some values in parachain inherents for tests
kishansagathiya Sep 29, 2022
e414ecf
Merge branch 'kishan/feat/parachain-inherents' of github.com:ChainSaf…
kishansagathiya Sep 29, 2022
d5affe4
more non-zero values
kishansagathiya Sep 29, 2022
d0eab91
revert scale map encoding changes
kishansagathiya Sep 30, 2022
25d94a3
iterate through map in orderly way
kishansagathiya Sep 30, 2022
b176471
Merge branch 'development' into kishan/feat/parachain-inherents
kishansagathiya Sep 30, 2022
5e3d3c4
rename InherentsData to InherentData
kishansagathiya Sep 30, 2022
2601321
Merge branch 'development' into kishan/feat/parachain-inherents
kishansagathiya Oct 6, 2022
3572771
Merge branch 'development' into kishan/feat/parachain-inherents
kishansagathiya Oct 6, 2022
5e67259
Merge branch 'development' into kishan/feat/parachain-inherents
kishansagathiya Oct 7, 2022
e5ef1ed
hopefully final fix for having consistant order in scale encoding of
kishansagathiya Oct 7, 2022
d690816
Merge branch 'kishan/feat/parachain-inherents' of github.com:ChainSaf…
kishansagathiya Oct 7, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions dot/sync/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ func BuildBlock(t *testing.T, instance runtime.Instance, parent *types.Header, e
err = instance.InitializeBlock(header)
require.NoError(t, err)

idata := types.NewInherentsData()
err = idata.SetInt64Inherent(types.Timstap0, uint64(time.Now().Unix()))
idata := types.NewInherentData()
err = idata.SetInherent(types.Timstap0, uint64(time.Now().Unix()))
require.NoError(t, err)

err = idata.SetInt64Inherent(types.Babeslot, 1)
err = idata.SetInherent(types.Babeslot, uint64(1))
require.NoError(t, err)

ienc, err := idata.Encode()
Expand Down
6 changes: 3 additions & 3 deletions dot/types/babe_digest.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (d *BabePrimaryPreDigest) ToPreRuntimeDigest() (*PreRuntimeDigest, error) {
return toPreRuntimeDigest(*d)
}

// Index Returns VDT index
// Index returns VDT index
func (BabePrimaryPreDigest) Index() uint { return 1 }

// BabeSecondaryPlainPreDigest is included in a block built by a secondary slot authorized producer
Expand All @@ -83,7 +83,7 @@ func (d *BabeSecondaryPlainPreDigest) ToPreRuntimeDigest() (*PreRuntimeDigest, e
return toPreRuntimeDigest(*d)
}

// Index Returns VDT index
// Index returns VDT index
func (BabeSecondaryPlainPreDigest) Index() uint { return 2 }

// BabeSecondaryVRFPreDigest is included in a block built by a secondary slot authorized producer
Expand Down Expand Up @@ -111,7 +111,7 @@ func (d *BabeSecondaryVRFPreDigest) ToPreRuntimeDigest() (*PreRuntimeDigest, err
return toPreRuntimeDigest(*d)
}

// Index Returns VDT index
// Index returns VDT index
func (BabeSecondaryVRFPreDigest) Index() uint { return 3 }

// toPreRuntimeDigest returns the VaryingDataTypeValue as a PreRuntimeDigest
Expand Down
16 changes: 8 additions & 8 deletions dot/types/consensus_digest.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type GrandpaScheduledChange struct {
Delay uint32
}

// Index Returns VDT index
// Index returns VDT index
func (GrandpaScheduledChange) Index() uint { return 1 }

// GrandpaForcedChange represents a GRANDPA forced authority change
Expand All @@ -39,31 +39,31 @@ type GrandpaForcedChange struct {
Delay uint32
}

// Index Returns VDT index
// Index returns VDT index
func (GrandpaForcedChange) Index() uint { return 2 }

// GrandpaOnDisabled represents a GRANDPA authority being disabled
type GrandpaOnDisabled struct {
ID uint64
}

// Index Returns VDT index
// Index returns VDT index
func (GrandpaOnDisabled) Index() uint { return 3 }

// GrandpaPause represents an authority set pause
type GrandpaPause struct {
Delay uint32
}

// Index Returns VDT index
// Index returns VDT index
func (GrandpaPause) Index() uint { return 4 }

// GrandpaResume represents an authority set resume
type GrandpaResume struct {
Delay uint32
}

// Index Returns VDT index
// Index returns VDT index
func (GrandpaResume) Index() uint { return 5 }

// NextEpochData is the digest that contains the data for the upcoming BABE epoch.
Expand All @@ -73,7 +73,7 @@ type NextEpochData struct {
Randomness [RandomnessLength]byte
}

// Index Returns VDT index
// Index returns VDT index
func (NextEpochData) Index() uint { return 1 }

func (d NextEpochData) String() string {
Expand All @@ -98,7 +98,7 @@ type BABEOnDisabled struct {
ID uint32
}

// Index Returns VDT index
// Index returns VDT index
func (BABEOnDisabled) Index() uint { return 2 }

// NextConfigData is the digest that contains changes to the BABE configuration.
Expand All @@ -109,7 +109,7 @@ type NextConfigData struct {
SecondarySlots byte
}

// Index Returns VDT index
// Index returns VDT index
func (NextConfigData) Index() uint { return 3 }

// ToConfigData returns the NextConfigData as ConfigData
Expand Down
8 changes: 4 additions & 4 deletions dot/types/digest.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type ChangesTrieRootDigest struct {
Hash common.Hash
}

// Index Returns VDT index
// Index returns VDT index
func (ChangesTrieRootDigest) Index() uint { return 2 }

// String returns the digest as a string
Expand All @@ -58,7 +58,7 @@ type PreRuntimeDigest struct {
Data []byte
}

// Index Returns VDT index
// Index returns VDT index
func (PreRuntimeDigest) Index() uint { return 6 }

// NewBABEPreRuntimeDigest returns a PreRuntimeDigest with the BABE consensus ID
Expand All @@ -80,7 +80,7 @@ type ConsensusDigest struct {
Data []byte
}

// Index Returns VDT index
// Index returns VDT index
func (ConsensusDigest) Index() uint { return 4 }

// String returns the digest as a string
Expand All @@ -94,7 +94,7 @@ type SealDigest struct {
Data []byte
}

// Index Returns VDT index
// Index returns VDT index
func (SealDigest) Index() uint { return 5 }

// String returns the digest as a string
Expand Down
98 changes: 63 additions & 35 deletions dot/types/inherents.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,68 +5,87 @@ package types

import (
"bytes"
"encoding/binary"
"errors"
"fmt"
"math/big"
"reflect"

"github.com/ChainSafe/gossamer/pkg/scale"
)

var (
// Timstap0 is an inherent key.
Timstap0 = []byte("timstap0")
// Babeslot is an inherent key.
Babeslot = []byte("babeslot")
// Uncles00 is an inherent key.
Uncles00 = []byte("uncles00")
// InherentIdentifier is an identifier for an inherent.
type InherentIdentifier uint

const (
// Timstap0 is the identifier for the `timestamp` inherent.
Timstap0 InherentIdentifier = iota
// Babeslot is the BABE inherent identifier.
Babeslot
// Uncles00 is the identifier for the `uncles` inherent.
Uncles00
// Parachn0 is an inherent key for parachains inherent.
Parachn0
// Newheads is an inherent key for new minimally-attested parachain heads.
Newheads
)

// InherentsData contains a mapping of inherent keys to values
// Bytes returns a byte array of given inherent identifier.
func (ii InherentIdentifier) Bytes() [8]byte {

kb := [8]byte{}
Comment on lines +32 to +34
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

Suggested change
func (ii InherentIdentifier) Bytes() [8]byte {
kb := [8]byte{}
func (ii InherentIdentifier) Bytes() (kb [8]byte) {

switch ii {
case Timstap0:
copy(kb[:], []byte("timstap0"))
case Babeslot:
copy(kb[:], []byte("babeslot"))
case Uncles00:
copy(kb[:], []byte("uncles00"))
case Parachn0:
copy(kb[:], []byte("parachn0"))
case Newheads:
copy(kb[:], []byte("newheads"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit why is it named kb? Shouldn't it be inherentIndentifier / identifier / identifierBytes

default:
panic("invalid inherent identifier")
}

return kb
}

// InherentData contains a mapping of inherent keys to values
// keys must be 8 bytes, values are a scale-encoded byte array
type InherentsData struct {
data map[[8]byte]([]byte)
type InherentData struct {
Data map[[8]byte][]byte
kishansagathiya marked this conversation as resolved.
Show resolved Hide resolved
}

// NewInherentsData returns InherentsData
func NewInherentsData() *InherentsData {
return &InherentsData{
data: make(map[[8]byte]([]byte)),
// NewInherentData returns InherentData
func NewInherentData() *InherentData {
return &InherentData{
Data: make(map[[8]byte][]byte),
}
}

func (d *InherentsData) String() string {
func (d *InherentData) String() string {
str := ""
for k, v := range d.data {
for k, v := range d.Data {
str = str + fmt.Sprintf("key=%v\tvalue=%v\n", k, v)
}
return str
}

// SetInt64Inherent set an inherent of type uint64
func (d *InherentsData) SetInt64Inherent(key []byte, data uint64) error {
if len(key) != 8 {
return errors.New("inherent key must be 8 bytes")
}

val := make([]byte, 8)
binary.LittleEndian.PutUint64(val, data)

venc, err := scale.Marshal(val)
// SetInherent sets a inherent.
func (d *InherentData) SetInherent(inherentIdentifier InherentIdentifier, value any) error {
data, err := scale.Marshal(value)
if err != nil {
return err
kishansagathiya marked this conversation as resolved.
Show resolved Hide resolved
}

kb := [8]byte{}
copy(kb[:], key)
d.Data[inherentIdentifier.Bytes()] = data

d.data[kb] = venc
return nil
}

// Encode will encode a given []byte using scale.Encode
func (d *InherentsData) Encode() ([]byte, error) {
length := big.NewInt(int64(len(d.data)))
func (d *InherentData) Encode() ([]byte, error) {
length := big.NewInt(int64(len(d.Data)))
buffer := bytes.Buffer{}

l, err := scale.Marshal(length)
Expand All @@ -79,15 +98,24 @@ func (d *InherentsData) Encode() ([]byte, error) {
return nil, err
}

for k, v := range d.data {
for i := reflect.ValueOf(d.Data).MapRange(); i.Next(); {
k := i.Key().Interface().([8]byte)
v := i.Value().Interface().([]byte)

_, err = buffer.Write(k[:])
if err != nil {
return nil, err
}
_, err = buffer.Write(v)

venc, err := scale.Marshal(v)
if err != nil {
return nil, fmt.Errorf("scale encoding encoded value: %w", err)
}
_, err = buffer.Write(venc)
if err != nil {
return nil, err
}
}

return buffer.Bytes(), nil
}
45 changes: 45 additions & 0 deletions dot/types/inherents_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2022 ChainSafe Systems (ON)
// SPDX-License-Identifier: LGPL-3.0-only

package types

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestInherentDataMarshal(t *testing.T) {
tests := []struct {
name string
getInherentData func(t *testing.T) *InherentData
want []byte
}{
{
/*
let mut data = InherentData::new();
let timestamp: u64 = 99;
data.put_data(*b"babeslot", &timestamp).unwrap();
data.put_data(*b"timstap0", &timestamp).unwrap();
*/
getInherentData: func(t *testing.T) *InherentData {
id := NewInherentData()
err := id.SetInherent(Babeslot, uint64(99))
require.NoError(t, err)

err = id.SetInherent(Timstap0, uint64(99))
require.NoError(t, err)
return id
},
want: []byte{8, 98, 97, 98, 101, 115, 108, 111, 116, 32, 99, 0, 0, 0, 0, 0, 0, 0, 116, 105, 109, 115, 116, 97, 112, 48, 32, 99, 0, 0, 0, 0, 0, 0, 0}, //nolint:lll
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
idata := tt.getInherentData(t)
got, err := idata.Encode()
require.NoError(t, err)
require.Equal(t, tt.want, got)
})
}
}
26 changes: 21 additions & 5 deletions lib/babe/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (b *BlockBuilder) buildBlock(parent *types.Header, slot Slot, rt runtime.In
logger.Trace("initialised block")

// add block inherents
inherents, err := buildBlockInherents(slot, rt)
inherents, err := buildBlockInherents(slot, rt, parent)
if err != nil {
return nil, fmt.Errorf("cannot build inherents: %s", err)
}
Expand Down Expand Up @@ -222,21 +222,37 @@ func (b *BlockBuilder) buildBlockExtrinsics(slot Slot, rt runtime.Instance) []*t
return included
}

func buildBlockInherents(slot Slot, rt runtime.Instance) ([][]byte, error) {
func buildBlockInherents(slot Slot, rt runtime.Instance, parent *types.Header) ([][]byte, error) {
// Setup inherents: add timstap0
idata := types.NewInherentsData()
idata := types.NewInherentData()
timestamp := uint64(time.Now().UnixMilli())
err := idata.SetInt64Inherent(types.Timstap0, timestamp)
err := idata.SetInherent(types.Timstap0, timestamp)
if err != nil {
return nil, err
}

// add babeslot
err = idata.SetInt64Inherent(types.Babeslot, slot.number)
err = idata.SetInherent(types.Babeslot, slot.number)
if err != nil {
return nil, err
}

parachainInherent := ParachainInherentData{
kishansagathiya marked this conversation as resolved.
Show resolved Hide resolved
ParentHeader: *parent,
}

// add parachn0 and newheads
// for now we can use "empty" values, as we require parachain-specific
// logic to actually provide the data.

if err = idata.SetInherent(types.Parachn0, parachainInherent); err != nil {
return nil, fmt.Errorf("setting inherent %q: %w", types.Parachn0, err)
}

if err = idata.SetInherent(types.Newheads, []byte{0}); err != nil {
return nil, fmt.Errorf("setting inherent %q: %w", types.Newheads, err)
}

ienc, err := idata.Encode()
if err != nil {
return nil, err
Expand Down
Loading