Skip to content

Commit

Permalink
Hotfix-sortedProposedBlocks (#957)
Browse files Browse the repository at this point in the history
* Shuffled copied slice instead of original slice

* returned error from giveSorted when len(sortedValues)=0

* Fixed dispute tests
  • Loading branch information
Yashk767 authored Sep 30, 2022
1 parent 0e01a74 commit afe4923
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 127 deletions.
8 changes: 4 additions & 4 deletions cmd/dispute.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (*UtilsStruct) HandleDispute(client *ethclient.Client, config types.Configu
log.Debug("Revealed collection ids:", revealedCollectionIds)
log.Debug("Local revealed data maps:", revealedDataMaps)

randomSortedProposedBlockIds := utils.UtilsInterface.Shuffle(sortedProposedBlockIds) //shuffles the sortedProposedBlockIds array
randomSortedProposedBlockIds := utils.Shuffle(sortedProposedBlockIds) //shuffles the sortedProposedBlockIds array
transactionOptions := types.TransactionOptions{
Client: client,
Password: account.Password,
Expand All @@ -64,7 +64,7 @@ func (*UtilsStruct) HandleDispute(client *ethclient.Client, config types.Configu
log.Debug("Shuffled sorted proposed blocks: ", randomSortedProposedBlockIds)

for _, blockId := range randomSortedProposedBlockIds {
proposedBlock, err := razorUtils.GetProposedBlock(client, epoch, uint32(blockId))
proposedBlock, err := razorUtils.GetProposedBlock(client, epoch, blockId)
if err != nil {
log.Error(err)
continue
Expand All @@ -73,7 +73,7 @@ func (*UtilsStruct) HandleDispute(client *ethclient.Client, config types.Configu
log.Debug("Proposed block ", proposedBlock)

//blockIndex is index of blockId in sortedProposedBlock
blockIndex := utils.IndexOf(sortedProposedBlockIds, uint32(blockId))
blockIndex := utils.IndexOf(sortedProposedBlockIds, blockId)
if blockIndex == -1 {
log.Error("Block is not present in SortedProposedBlockIds array")
continue
Expand Down Expand Up @@ -387,7 +387,7 @@ func (*UtilsStruct) Dispute(client *ethclient.Client, config types.Configuration
//This function sorts the Id's recursively
func GiveSorted(client *ethclient.Client, blockManager *bindings.BlockManager, txnArgs types.TransactionOptions, epoch uint32, leafId uint16, sortedValues []*big.Int) error {
if len(sortedValues) == 0 {
return nil
return errors.New("length of sortedValues is 0")
}
callOpts := razorUtils.GetOptions()
txnOpts := razorUtils.GetTxnOpts(txnArgs)
Expand Down
Loading

0 comments on commit afe4923

Please sign in to comment.