Skip to content

Commit

Permalink
[master-2.x] Fix Transaction verify (#2009)
Browse files Browse the repository at this point in the history
* Fix transaction verification

* fix

Co-authored-by: Jin Qiao <jinqiao@neo.org>
  • Loading branch information
Qiao-Jin and Jin Qiao committed Oct 26, 2020
1 parent e18d431 commit 9b0391d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
1 change: 1 addition & 0 deletions neo.UnitTests/TestBlockchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public static NeoSystem InitializeMockNeoSystem()
mockStore.Setup(p => p.GetContracts()).Returns(new TestDataCache<UInt160, ContractState>());
mockStore.Setup(p => p.GetStorages()).Returns(new TestDataCache<StorageKey, StorageItem>());
mockStore.Setup(p => p.GetHeaderHashList()).Returns(new TestDataCache<UInt32Wrapper, HeaderHashList>());
mockStore.Setup(p => p.GetStateRoots()).Returns(new TestDataCache<UInt32Wrapper, StateRootState>());
mockStore.Setup(p => p.GetValidatorsCount()).Returns(new TestMetaDataCache<ValidatorsCountState>());
mockStore.Setup(p => p.GetBlockHashIndex()).Returns(new TestMetaDataCache<HashIndexState>());
mockStore.Setup(p => p.GetHeaderHashIndex()).Returns(new TestMetaDataCache<HashIndexState>());
Expand Down
16 changes: 9 additions & 7 deletions neo/Network/P2P/Payloads/Transaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,24 +82,26 @@ public virtual Fixed8 NetworkFee
}

private IReadOnlyDictionary<CoinReference, TransactionOutput> _references;
private bool hasCalculatedReferences = false;
public IReadOnlyDictionary<CoinReference, TransactionOutput> References
{
get
{
if (_references == null)
if (!hasCalculatedReferences && _references == null)
{
hasCalculatedReferences = true;
Dictionary<CoinReference, TransactionOutput> dictionary = new Dictionary<CoinReference, TransactionOutput>();
foreach (var group in Inputs.GroupBy(p => p.PrevHash))
{
Transaction tx = Blockchain.Singleton.Store.GetTransaction(group.Key);
if (tx == null) return null;
foreach (var reference in group.Select(p => new
foreach (var reference in group)
{
Input = p,
Output = tx.Outputs[p.PrevIndex]
}))
{
dictionary.Add(reference.Input, reference.Output);
if (reference.PrevIndex >= Outputs.Length)
{
return null;
}
dictionary.Add(reference, tx.Outputs[reference.PrevIndex]);
}
}
_references = dictionary;
Expand Down

0 comments on commit 9b0391d

Please sign in to comment.