Skip to content

Commit

Permalink
Fix NeoToken.OnPersist()
Browse files Browse the repository at this point in the history
  • Loading branch information
erikzhang committed Aug 25, 2020
1 parent 765c43a commit 7032907
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/neo/SmartContract/Native/Tokens/NeoToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,17 @@ protected override void OnPersist(ApplicationEngine engine)

// Distribute GAS for committee

int index = (int)(engine.Snapshot.PersistingBlock.Index % (uint)ProtocolSettings.Default.CommitteeMembersCount);
var gasPerBlock = GetGasPerBlock(engine.Snapshot);
var committee = GetCommitteeMembers(engine.Snapshot).ToArray();
var pubkey = committee[engine.Snapshot.PersistingBlock.Index % ProtocolSettings.Default.CommitteeMembersCount];
var pubkey = committee.OrderBy(p => p).ElementAt(index);
var account = Contract.CreateSignatureRedeemScript(pubkey).ToScriptHash();
GAS.Mint(engine, account, gasPerBlock * CommitteeRewardRatio / 100);

// Set next validators

StorageItem storage = engine.Snapshot.Storages.GetAndChange(CreateStorageKey(Prefix_NextValidators), () => new StorageItem());
storage.Value = committee[..ProtocolSettings.Default.ValidatorsCount].ToByteArray();
storage.Value = committee.Take(ProtocolSettings.Default.ValidatorsCount).OrderBy(p => p).ToArray().ToByteArray();
}

[ContractMethod(0_05000000, CallFlags.AllowModifyStates)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ public void Check_CommitteeBonus()
engine.Execute();
engine.State.Should().Be(VM.VMState.HALT);

var committee = Blockchain.StandbyCommittee;
var committee = Blockchain.StandbyCommittee.OrderBy(p => p).ToArray();
NativeContract.GAS.BalanceOf(snapshot, Contract.CreateSignatureContract(committee[0]).ScriptHash.ToArray()).Should().Be(25000000);
NativeContract.GAS.BalanceOf(snapshot, Contract.CreateSignatureContract(committee[1]).ScriptHash.ToArray()).Should().Be(0);
}
Expand Down

0 comments on commit 7032907

Please sign in to comment.