Sitelet https://github.com/Fantom-foundation/Sonic/commit/85d877e01dde25b61cfa698278ef43f3c698e207
Skip to content

Commit 85d877e

Browse files
committed
update lachesis-base version
1 parent 735a51d commit 85d877e

8 files changed

Lines changed: 22 additions & 20 deletions

File tree

‎eventcheck/basiccheck/basic_check.go‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"math"
66

77
base "github.com/Fantom-foundation/lachesis-base/eventcheck/basiccheck"
8+
"github.com/Fantom-foundation/lachesis-base/inter/idx"
89
"github.com/ethereum/go-ethereum/core/types"
910

1011
"github.com/Fantom-foundation/go-opera/evmcore"
@@ -74,8 +75,8 @@ func CalcGasPowerUsed(e inter.EventPayloadI, config *opera.DagConfig) uint64 {
7475
}
7576

7677
parentsGas := uint64(0)
77-
if uint32(len(e.Parents())) > config.MaxFreeParents {
78-
parentsGas = uint64(uint32(len(e.Parents()))-config.MaxFreeParents) * params.ParentGas
78+
if idx.Event(len(e.Parents())) > config.MaxFreeParents {
79+
parentsGas = uint64(idx.Event(len(e.Parents()))-config.MaxFreeParents) * params.ParentGas
7980
}
8081
extraGas := uint64(len(e.Extra())) * params.ExtraDataGas
8182

@@ -104,7 +105,7 @@ func (v *Checker) Validate(e inter.EventPayloadI) error {
104105
if e.CreationTime() <= 0 || e.MedianTime() <= 0 {
105106
return ErrZeroTime
106107
}
107-
if uint32(len(e.Parents())) > v.config.MaxParents {
108+
if idx.Event(len(e.Parents())) > v.config.MaxParents {
108109
return ErrTooManyParents
109110
}
110111
if err := v.checkGas(e); err != nil {

‎go.mod‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/Fantom-foundation/go-opera
33
go 1.14
44

55
require (
6-
github.com/Fantom-foundation/lachesis-base v0.0.0-20201209163541-2928fbd17ceb
6+
github.com/Fantom-foundation/lachesis-base v0.0.0-20201221134232-e82eb3d7a18a
77
github.com/allegro/bigcache v1.2.1 // indirect
88
github.com/aristanetworks/goarista v0.0.0-20191023202215-f096da5361bb // indirect
99
github.com/btcsuite/btcd v0.20.1-beta // indirect

‎go.sum‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ github.com/Azure/go-autorest/logger v0.1.0/go.mod h1:oExouG+K6PryycPJfVSxi/koC6L
1414
github.com/Azure/go-autorest/tracing v0.5.0/go.mod h1:r/s2XiOKccPW3HrqB+W0TQzfbtp2fGCgRFtBroKn4Dk=
1515
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
1616
github.com/DataDog/zstd v1.3.6-0.20190409195224-796139022798/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
17-
github.com/Fantom-foundation/lachesis-base v0.0.0-20201209163541-2928fbd17ceb h1:RqH1WmLxmpE/DM8344p1KZFahTIFfNUSrQwfpJSW5PY=
18-
github.com/Fantom-foundation/lachesis-base v0.0.0-20201209163541-2928fbd17ceb/go.mod h1:E6+2LOvgADwSOv0U5YXhRJz4PlX8qJxvq8M93AOC1tM=
17+
github.com/Fantom-foundation/lachesis-base v0.0.0-20201221134232-e82eb3d7a18a h1:ipzJxHaM9XMc3WEFy17Lyc+JyWKHIbp8nW6Wa/kikKU=
18+
github.com/Fantom-foundation/lachesis-base v0.0.0-20201221134232-e82eb3d7a18a/go.mod h1:E6+2LOvgADwSOv0U5YXhRJz4PlX8qJxvq8M93AOC1tM=
1919
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
2020
github.com/Shopify/sarama v1.23.1/go.mod h1:XLH1GYJnLVE0XCr6KdJGVJRTwY30moWNJ4sERjXX6fs=
2121
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=

‎gossip/blockproc/sealmodule/sealer.go‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package sealmodule
22

33
import (
4+
"github.com/Fantom-foundation/lachesis-base/inter/idx"
45
"github.com/Fantom-foundation/lachesis-base/inter/pos"
56

67
"github.com/Fantom-foundation/go-opera/gossip/blockproc"
@@ -65,11 +66,11 @@ func (s *OperaEpochsSealer) SealEpoch() (blockproc.BlockState, blockproc.EpochSt
6566
// Build new []ValidatorEpochState and []ValidatorBlockState
6667
newValidatorEpochStates := make([]blockproc.ValidatorEpochState, newValidators.Len())
6768
newValidatorBlockStates := make([]blockproc.ValidatorBlockState, newValidators.Len())
68-
for newValIdx := 0; newValIdx < newValidators.Len(); newValIdx++ {
69+
for newValIdx := idx.Validator(0); newValIdx < newValidators.Len(); newValIdx++ {
6970
// default values
7071
newValidatorBlockStates[newValIdx] = blockproc.DefaultValidatorBlockState
7172
// inherit validator's state from previous epoch, if any
72-
valID := newValidators.SortedIDs()[newValIdx]
73+
valID := newValidators.GetID(newValIdx)
7374
if !oldValidators.Exists(valID) {
7475
continue
7576
}

‎gossip/blockproc/sfcmodule/sfc_txs.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func (p *SfcTxPreTransactor) PopInternalTxs(block blockproc.BlockCtx, bs blockpr
132132
// push data into SFC before epoch sealing
133133
if sealing {
134134
metrics := make([]sfccall.ValidatorEpochMetric, es.Validators.Len())
135-
for oldValIdx := 0; oldValIdx < es.Validators.Len(); oldValIdx++ {
135+
for oldValIdx := idx.Validator(0); oldValIdx < es.Validators.Len(); oldValIdx++ {
136136
info := bs.ValidatorStates[oldValIdx]
137137
missed := opera.BlocksMissed{
138138
BlocksNum: block.Idx - info.LastBlock,

‎opera/rules.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ type GasPowerConfig struct {
4444

4545
// DagConfig of Lachesis DAG (directed acyclic graph).
4646
type DagConfig struct {
47-
MaxParents uint32
48-
MaxFreeParents uint32 // maximum number of parents with no gas cost
47+
MaxParents idx.Event
48+
MaxFreeParents idx.Event // maximum number of parents with no gas cost
4949

5050
MaxEpochBlocks idx.Block
5151
MaxEpochDuration inter.Timestamp

‎utils/weighted_shuffle.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,24 +50,24 @@ func (t *weightedShuffleTree) build(i int) pos.Weight {
5050
return thisW + leftW + rightW
5151
}
5252

53-
func (t *weightedShuffleTree) rand64() uint64 {
53+
func (t *weightedShuffleTree) rand32() uint32 {
5454
if t.seedIndex == 32 {
5555
hasher := sha256.New() // use sha2 instead of sha3 for speed
5656
hasher.Write(t.seed.Bytes())
5757
t.seed = hash.BytesToHash(hasher.Sum(nil))
5858
t.seedIndex = 0
5959
}
6060
// use not used parts of old seed, instead of calculating new one
61-
res := littleendian.BytesToUint64(t.seed[t.seedIndex : t.seedIndex+8])
62-
t.seedIndex += 8
61+
res := littleendian.BytesToUint32(t.seed[t.seedIndex : t.seedIndex+4])
62+
t.seedIndex += 4
6363
return res
6464
}
6565

6666
func (t *weightedShuffleTree) retrieve(i int) int {
6767
node := t.nodes[i]
6868
total := node.rightWeight + node.leftWeight + node.thisWeight
6969

70-
r := pos.Weight(t.rand64()) % total
70+
r := pos.Weight(t.rand32()) % total
7171

7272
if r < node.thisWeight {
7373
t.nodes[i].thisWeight = 0

‎utils/weighted_shuffle_test.go‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ func Test_Permutation_determinism(t *testing.T) {
9191

9292
assertar := assert.New(t)
9393

94-
assertar.Equal([]int{3, 2, 4, 1, 0}, WeightedPermutation(len(weightsArr), weightsArr, hashOf(hash.Hash{}, 0)))
95-
assertar.Equal([]int{0, 4, 2, 1, 3}, WeightedPermutation(len(weightsArr), weightsArr, hashOf(hash.Hash{}, 1)))
96-
assertar.Equal([]int{3, 4, 2, 1, 0}, WeightedPermutation(len(weightsArr), weightsArr, hashOf(hash.Hash{}, 2)))
97-
assertar.Equal([]int{4, 2, 1, 3, 0}, WeightedPermutation(len(weightsArr), weightsArr, hashOf(hash.Hash{}, 3)))
98-
assertar.Equal([]int{1, 4}, WeightedPermutation(len(weightsArr)/2, weightsArr, hashOf(hash.Hash{}, 4)))
94+
assertar.Equal([]int{4, 0, 1, 2, 3}, WeightedPermutation(len(weightsArr), weightsArr, hashOf(hash.Hash{}, 0)))
95+
assertar.Equal([]int{2, 4, 3, 1, 0}, WeightedPermutation(len(weightsArr), weightsArr, hashOf(hash.Hash{}, 1)))
96+
assertar.Equal([]int{4, 2, 3, 1, 0}, WeightedPermutation(len(weightsArr), weightsArr, hashOf(hash.Hash{}, 2)))
97+
assertar.Equal([]int{0, 2, 1, 3, 4}, WeightedPermutation(len(weightsArr), weightsArr, hashOf(hash.Hash{}, 3)))
98+
assertar.Equal([]int{1, 2}, WeightedPermutation(len(weightsArr)/2, weightsArr, hashOf(hash.Hash{}, 4)))
9999
}

0 commit comments

Comments
 (0)