diff --git a/neo.UnitTests/TestBlockchain.cs b/neo.UnitTests/TestBlockchain.cs index 9e481e4e61..b3deab3039 100644 --- a/neo.UnitTests/TestBlockchain.cs +++ b/neo.UnitTests/TestBlockchain.cs @@ -52,6 +52,7 @@ public static NeoSystem InitializeMockNeoSystem() mockStore.Setup(p => p.GetContracts()).Returns(new TestDataCache()); mockStore.Setup(p => p.GetStorages()).Returns(new TestDataCache()); mockStore.Setup(p => p.GetHeaderHashList()).Returns(new TestDataCache()); + mockStore.Setup(p => p.GetStateRoots()).Returns(new TestDataCache()); mockStore.Setup(p => p.GetValidatorsCount()).Returns(new TestMetaDataCache()); mockStore.Setup(p => p.GetBlockHashIndex()).Returns(new TestMetaDataCache()); mockStore.Setup(p => p.GetHeaderHashIndex()).Returns(new TestMetaDataCache()); diff --git a/neo/Network/P2P/Payloads/Transaction.cs b/neo/Network/P2P/Payloads/Transaction.cs index 123fc3ba6e..d84cb909f6 100644 --- a/neo/Network/P2P/Payloads/Transaction.cs +++ b/neo/Network/P2P/Payloads/Transaction.cs @@ -82,24 +82,26 @@ public virtual Fixed8 NetworkFee } private IReadOnlyDictionary _references; + private bool hasCalculatedReferences = false; public IReadOnlyDictionary References { get { - if (_references == null) + if (!hasCalculatedReferences && _references == null) { + hasCalculatedReferences = true; Dictionary dictionary = new Dictionary(); 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;