-
Notifications
You must be signed in to change notification settings - Fork 222
Fix multiple headers not being referenced #7581
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
Changes from 4 commits
1d3b079
2fe6050
d0b998f
4679907
ed2a868
ade3ae0
6b421eb
37e76be
75782c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ import ( | |
| const ( | ||
| incoming = "incoming" | ||
| outgoing = "outgoing" | ||
| pending = "pending" | ||
| ) | ||
|
|
||
| const ( | ||
|
|
@@ -125,6 +126,19 @@ func (gc *gasConsumption) AddIncomingMiniBlocks( | |
| for _, mb := range miniBlocks[i:] { | ||
| hashStr := string(mb.GetHash()) | ||
| gc.transactionsForPendingMiniBlocks[hashStr] = transactions[hashStr] | ||
|
|
||
| transactionsForMB, found := transactions[string(mb.GetHash())] | ||
| if !found { | ||
| log.Warn("could not find transaction for pending mini block", "hash", mb.GetHash()) | ||
| continue | ||
| } | ||
| gasConsumedByPendingMb, errCheckPending := gc.checkGasConsumedByMiniBlock(mb, transactionsForMB) | ||
| if errCheckPending != nil { | ||
| log.Warn("failed to check gas consumed by pending mini block", "hash", mb.GetHash(), "error", errCheckPending) | ||
| continue | ||
|
||
| } | ||
|
|
||
| gc.totalGasConsumed[pending] += gasConsumedByPendingMb | ||
| } | ||
|
|
||
| return lastMiniBlockIndex, len(gc.pendingMiniBlocks), err | ||
|
|
@@ -155,6 +169,7 @@ func (gc *gasConsumption) RevertIncomingMiniBlocks(miniBlockHashes [][]byte) { | |
| isPending, idxInPendingSlice := gc.isPendingMiniBlock(miniBlockHash) | ||
| if isPending { | ||
| gc.revertPendingMiniBlock(miniBlockHash, idxInPendingSlice) | ||
| gc.totalGasConsumed[pending] -= gasConsumedByMb | ||
| continue | ||
| } | ||
|
|
||
|
|
@@ -281,6 +296,7 @@ func (gc *gasConsumption) addPendingIncomingMiniBlocks() ([]data.MiniBlockHeader | |
| lastIndexAdded := 0 | ||
| for i := 0; i < len(gc.pendingMiniBlocks); i++ { | ||
| mb := gc.pendingMiniBlocks[i] | ||
| gasConsumedByIncomingBefore := gc.totalGasConsumed[incoming] | ||
| shouldSavePending, err := gc.addIncomingMiniBlock(mb, gc.transactionsForPendingMiniBlocks, bandwidthForIncomingMiniBlocks) | ||
| if err != nil { | ||
| return nil, err | ||
|
|
@@ -292,6 +308,13 @@ func (gc *gasConsumption) addPendingIncomingMiniBlocks() ([]data.MiniBlockHeader | |
|
|
||
| addedMiniBlocks = append(addedMiniBlocks, mb) | ||
| lastIndexAdded = i | ||
|
|
||
| gasConsumedByIncomingAfter := gc.totalGasConsumed[incoming] | ||
| gasConsumedByMiniBlock := gasConsumedByIncomingAfter - gasConsumedByIncomingBefore | ||
| if gasConsumedByMiniBlock < gc.totalGasConsumed[pending] { | ||
|
||
| // should never be false | ||
| gc.totalGasConsumed[pending] -= gasConsumedByMiniBlock | ||
| } | ||
| } | ||
|
|
||
| gc.pendingMiniBlocks = gc.pendingMiniBlocks[lastIndexAdded+1:] | ||
|
|
@@ -471,6 +494,32 @@ func (gc *gasConsumption) TotalGasConsumedInShard(shard uint32) uint64 { | |
| return gc.totalGasConsumed[gasKeyOutgoingCross] | ||
| } | ||
|
|
||
| // CanAddPendingIncomingMiniBlocks returns true if more pending incoming mini blocks can be added without reaching the block limits | ||
| func (gc *gasConsumption) CanAddPendingIncomingMiniBlocks() bool { | ||
| gc.mut.RLock() | ||
| defer gc.mut.RUnlock() | ||
|
|
||
| totalGasToBeConsumedByPending := uint64(0) | ||
| totalGasConsumed := uint64(0) | ||
| for typeOfGas, gasConsumed := range gc.totalGasConsumed { | ||
| if typeOfGas == pending { | ||
| totalGasToBeConsumedByPending += gasConsumed | ||
| continue | ||
| } | ||
|
|
||
| totalGasConsumed += gasConsumed | ||
| } | ||
|
|
||
| maxGasLimitPerBlock := gc.maxGasLimitPerBlock(incoming, gc.shardCoordinator.SelfId()) | ||
| if maxGasLimitPerBlock <= totalGasConsumed { | ||
| return false | ||
| } | ||
|
|
||
| gasLeft := maxGasLimitPerBlock - totalGasConsumed | ||
| maxGasLimitPerMiniBlock := gc.maxGasLimitPerMiniBlock(gc.shardCoordinator.SelfId()) | ||
| return totalGasToBeConsumedByPending+maxGasLimitPerMiniBlock < gasLeft | ||
|
||
| } | ||
|
|
||
| // DecreaseIncomingLimit reduces the gas limit for incoming mini blocks by a configured percentage | ||
| func (gc *gasConsumption) DecreaseIncomingLimit() { | ||
| gc.mut.Lock() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you merge this line and L128?
both appear to be reading the same transactions
e.g do the gc.transactionsForPendingMiniBlocks[hashStr] = transactionsForMB after the !found check?
or do we need to set nil explicitly in the map?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated, missed it