Skip to content

Commit

Permalink
Update txs.go
Browse files Browse the repository at this point in the history
test restricted subcommittee for txs emissions
  • Loading branch information
jacklevin74 authored Mar 28, 2024
1 parent a4f8b4d commit 975ebce
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions gossip/emitter/txs.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,21 +111,38 @@ func getTxRoundIndex(now, txTime time.Time, validatorsNum idx.Validator) int {
return int((passed / TxTurnPeriod) % time.Duration(validatorsNum))
}

// safe for concurrent use

// filterValidators creates a new pos.Validators object containing only validators with the specified IDs.
func filterValidators(vv *pos.Validators, allowedIDs []idx.ValidatorID) *pos.Validators {
builder := pos.NewBuilder() // Use the NewBuilder function to start building a new Validators object.
for _, id := range allowedIDs {
weight := vv.Get(id) // Use the Get method to retrieve the weight for each validator ID.
if weight != 0 { // If the validator exists (weight > 0), include it in the new Validators object.
builder.Set(id, weight)
}
}
return builder.Build() // Build and return the new Validators object.
}

func (em *Emitter) isMyTxTurn(txHash common.Hash, sender common.Address, accountNonce uint64, now time.Time, validators *pos.Validators, me idx.ValidatorID, epoch idx.Epoch) bool {
txTime := txtime.Of(txHash)
txTime := txtime.Of(txHash)

roundIndex := getTxRoundIndex(now, txTime, validators.Len())
if roundIndex != getTxRoundIndex(now.Add(TxTurnPeriodLatency), txTime, validators.Len()) {
// round is about to change, avoid originating the transaction to avoid racing with another validator
return false
}
// Use the helper function to create a new Validators object with only the specified IDs.
filteredValidators := filterValidators(validators, []idx.ValidatorID{1, 2, 3, 7, 21})

roundsHash := hash.Of(sender.Bytes(), bigendian.Uint64ToBytes(accountNonce/TxTurnNonces), epoch.Bytes())
rounds := utils.WeightedPermutation(roundIndex+1, validators.SortedWeights(), roundsHash)
return validators.GetID(idx.Validator(rounds[roundIndex])) == me
roundIndex := getTxRoundIndex(now, txTime, filteredValidators.Len())
if roundIndex != getTxRoundIndex(now.Add(TxTurnPeriodLatency), txTime, filteredValidators.Len()) {
// Round is about to change, avoid originating the transaction to avoid racing with another validator.
return false
}

roundsHash := hash.Of(sender.Bytes(), bigendian.Uint64ToBytes(accountNonce/TxTurnNonces), epoch.Bytes())
rounds := utils.WeightedPermutation(roundIndex+1, filteredValidators.SortedWeights(), roundsHash)
return filteredValidators.GetID(idx.Validator(rounds[roundIndex])) == me
}



func (em *Emitter) addTxs(e *inter.MutableEventPayload, sorted *types.TransactionsByPriceAndNonce) {
maxGasUsed := em.maxGasPowerToUse(e)
if maxGasUsed <= e.GasPowerUsed() {
Expand Down

0 comments on commit 975ebce

Please sign in to comment.