From 975ebce672d0e76fd67542d5714ec178fad032ec Mon Sep 17 00:00:00 2001 From: jacklevin74 Date: Thu, 28 Mar 2024 09:52:23 -0700 Subject: [PATCH] Update txs.go test restricted subcommittee for txs emissions --- gossip/emitter/txs.go | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/gossip/emitter/txs.go b/gossip/emitter/txs.go index c2bc58594..b7fb05e81 100644 --- a/gossip/emitter/txs.go +++ b/gossip/emitter/txs.go @@ -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() {