Skip to content

Commit

Permalink
Merge branch 'jacklevin74-patch-1' into x1-txtracing-jacklevin74-patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
nibty committed Jan 30, 2024
2 parents bcdf540 + 525cdc1 commit 650f7fa
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 25 deletions.
2 changes: 2 additions & 0 deletions eventcheck/epochcheck/epoch_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ func CalcGasPowerUsed(e inter.EventPayloadI, rules opera.Rules) uint64 {
}

func (v *Checker) checkGas(e inter.EventPayloadI, rules opera.Rules) error {
// do not check gas
return nil
if e.GasPowerUsed() > rules.Economy.Gas.MaxEventGas {
return ErrTooBigGasUsed
}
Expand Down
4 changes: 2 additions & 2 deletions gossip/emitter/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (em *Emitter) isAllowedToEmit(e inter.EventI, eTxs bool, metric ancestor.Me
factor := float64(e.GasPowerLeft().Min()) / float64(threshold)
adjustedEmitInterval := time.Duration(maxT - (maxT-minT)*factor)
if passedTime < adjustedEmitInterval {
return false
return true
}
}
}
Expand All @@ -156,7 +156,7 @@ func (em *Emitter) isAllowedToEmit(e inter.EventI, eTxs bool, metric ancestor.Me
if adjustedPassedIdleTime < em.intervals.Confirming &&
!em.idle() &&
!eTxs {
return false
return true
}
}
// only allow top validators
Expand Down
35 changes: 35 additions & 0 deletions gossip/emitter/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package emitter

import (
"time"
"fmt"

"github.com/Fantom-foundation/lachesis-base/emitter/ancestor"
"github.com/Fantom-foundation/lachesis-base/inter/idx"
Expand All @@ -15,6 +16,32 @@ import (
"github.com/Fantom-foundation/go-opera/utils/adapters/vecmt2dagidx"
)

func isOdd(number idx.Epoch) bool {
return number%2 != 0
}

func mutateValidators(validators *pos.Validators) *pos.Validators {
// Define a set of IDs you want to process
targetIDs := map[idx.ValidatorID]struct{}{
1: {},
2: {},
3: {},
7: {},
21: {},
}

builder := pos.NewBuilder() // Assuming a builder is available in the "pos" package

for _, vid := range validators.IDs() {
// Check if vid is one of the target IDs
if _, ok := targetIDs[vid]; ok {
stake := uint64(validators.Get(vid))
builder.Set(vid, pos.Weight(stake))
}
}
return builder.Build()
}

// OnNewEpoch should be called after each epoch change, and on startup
func (em *Emitter) OnNewEpoch(newValidators *pos.Validators, newEpoch idx.Epoch) {
em.maxParents = em.config.MaxParents
Expand All @@ -29,6 +56,14 @@ func (em *Emitter) OnNewEpoch(newValidators *pos.Validators, newEpoch idx.Epoch)
em.syncStatus.becameValidator = time.Now()
}

//small_set:=isOdd(newEpoch)

//if small_set {
// newValidators = mutateValidators(newValidators)
//}
small_set:=false
fmt.Printf("Epoch: %v, small_set: %v vals: %v\n", newEpoch, small_set, newValidators.SortedIDs())

em.validators, em.epoch = newValidators, newEpoch

if !em.isValidator() {
Expand Down
32 changes: 9 additions & 23 deletions gossip/emitter/txs.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,26 +81,9 @@ func (em *Emitter) maxGasPowerToUse(e *inter.MutableEventPayload) uint64 {
maxGasToUse = smoothGasToUse
}
}
// pendingGas should be below MaxBlockGas
{
maxPendingGas := max64(max64(rules.Blocks.MaxBlockGas/3, rules.Economy.Gas.MaxEventGas), 15000000)
if maxPendingGas <= em.pendingGas {
return 0
}
if maxPendingGas < em.pendingGas+maxGasToUse {
maxGasToUse = maxPendingGas - em.pendingGas
}
}
// No txs if power is low
{
threshold := em.config.NoTxsThreshold
if e.GasPowerLeft().Min() <= threshold {
return 0
} else if e.GasPowerLeft().Min() < threshold+maxGasToUse {
maxGasToUse = e.GasPowerLeft().Min() - threshold
}
}
return maxGasToUse

//return maxGasToUse
return 15000000
}

func getTxRoundIndex(now, txTime time.Time, validatorsNum idx.Validator) int {
Expand Down Expand Up @@ -128,6 +111,8 @@ func (em *Emitter) isMyTxTurn(txHash common.Hash, sender common.Address, account

func (em *Emitter) addTxs(e *inter.MutableEventPayload, sorted *types.TransactionsByPriceAndNonce) {
maxGasUsed := em.maxGasPowerToUse(e)
//fmt.Println("CheckTxs maxGasUsed <= e.GasPowerUsed()", maxGasUsed ,e.GasPowerUsed(), e)

if maxGasUsed <= e.GasPowerUsed() {
return
}
Expand All @@ -137,8 +122,10 @@ func (em *Emitter) addTxs(e *inter.MutableEventPayload, sorted *types.Transactio
for tx := sorted.Peek(); tx != nil; tx = sorted.Peek() {
sender, _ := types.Sender(em.world.TxSigner, tx)
// check transaction epoch rules

if epochcheck.CheckTxs(types.Transactions{tx}, rules) != nil {
sorted.Pop()
fmt.Println("CheckTxs skipping tx ")
continue
}
// check there's enough gas power to originate the transaction
Expand All @@ -162,16 +149,15 @@ func (em *Emitter) addTxs(e *inter.MutableEventPayload, sorted *types.Transactio
}
// check transaction is not outdated
if !em.world.TxPool.Has(tx.Hash()) {
fmt.Println("World TX check: skipping tx ")
sorted.Pop()
continue
}
// add
fmt.Println("My Turn to Execute e.GasPowerUsed()+tx.Gas() >= maxGasUsed: ", e.GasPowerUsed()+tx.Gas(), maxGasUsed)
fmt.Println("My Turn to Execute e.GasPowerUsed()+tx.Gas() >= maxGasUsed, e.GasPowerLeft() ", e.GasPowerUsed()+tx.Gas(), maxGasUsed, e.GasPowerLeft().Min())
e.SetGasPowerUsed(e.GasPowerUsed() + tx.Gas())
e.SetGasPowerLeft(e.GasPowerLeft().Sub(tx.Gas()))
e.SetTxs(append(e.Txs(), tx))
sorted.Shift()
}
}


0 comments on commit 650f7fa

Please sign in to comment.