Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…coinFullNode into segwit
  • Loading branch information
zeptin committed Oct 26, 2019
2 parents f6f41c2 + aa35411 commit 15822b5
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ public void ExecuteContractTransaction(RuleContext context, Transaction transact
result.ErrorMessage,
deserializedCallData.Value.GasPrice,
txContext.TxOutValue,
deserializedCallData.Value.IsCreateContract ? null : deserializedCallData.Value.MethodName)
deserializedCallData.Value.IsCreateContract ? null : deserializedCallData.Value.MethodName,
txContext.BlockHeight)
{
BlockHash = context.ValidationContext.BlockToValidate.GetHash()
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@ public class ReadyBlockchain
public static string BitcoinRegTest150NoWallet = @"ReadyData/RegTest150NoWallet.zip";

public static string StratisXMainnet15K = @"ReadyData/StratisXOver15K.zip";
public static string StratisMainnet9500 = @"ReadyData/StratisMain9500.zip";
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
<None Update="ReadyData\RegTest150NoWallet.zip">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="ReadyData\StratisMain9500.zip">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="ReadyData\StratisRegTest100Listener.zip">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ public void Transaction_CreatedByXNode_TraversesSBFN_ReachesSecondXNode()
}

[Fact]
public void GatewayNodeCanSyncFirst15KBlocks()
public void GatewayNodeCanSyncBeforeAndAfterLastCheckpointPowAndPoS()
{
Network network = new StratisMain10KCheckpoint();

Expand All @@ -415,8 +415,11 @@ public void GatewayNodeCanSyncFirst15KBlocks()
var gatewayParameters = new NodeConfigParameters();
gatewayParameters.Add("regtest", "0");
gatewayParameters.Add("gateway", "1");
gatewayParameters.Add("txindex", "0");
gatewayParameters.Add("whitelist", stratisXNode.Endpoint.ToString());
CoreNode gatewayNode = builder.CreateStratisPosNode(network, configParameters: gatewayParameters, isGateway:true);
CoreNode gatewayNode =
builder.CreateStratisPosNode(network, configParameters: gatewayParameters, isGateway: true)
.WithReadyBlockchainData(ReadyBlockchain.StratisMainnet9500);

gatewayNode.Start();
stratisXNode.Start();
Expand All @@ -426,7 +429,7 @@ public void GatewayNodeCanSyncFirst15KBlocks()

gatewayNodeRpc.AddNode(stratisXNode.Endpoint);

TestBase.WaitLoop(() => gatewayNode.FullNode.ChainIndexer.Height >= 15_000, waitTimeSeconds: 600);
TestBase.WaitLoop(() => gatewayNode.FullNode.ChainIndexer.Height >= 13_000, waitTimeSeconds: 600);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,16 @@ public void Store_Basic_Receipt()
};
var log2 = new Log(new uint160(12345), topics2, data2);

var receipt = new Receipt(new uint256(1234), 12345, new Log[] { log1, log2 }, new uint256(12345), new uint160(25), new uint160(24), new uint160(23), true, "SomeResult", "SomeExceptionString", 54321, 1_000_000, "TestMethodName") { BlockHash = new uint256(1234) };
var receipt = new Receipt(new uint256(1234), 12345, new Log[] { log1, log2 }, new uint256(12345), new uint160(25), new uint160(24), new uint160(23), true, "SomeResult", "SomeExceptionString", 54321, 1_000_000, "TestMethodName", 123456) { BlockHash = new uint256(1234) };
this.db.Store(new Receipt[] { receipt });
Receipt retrievedReceipt = this.db.Retrieve(receipt.TransactionHash);
ReceiptSerializationTest.TestStorageReceiptEquality(receipt, retrievedReceipt);
}

[Fact]
public void Store_Receipt_With_Null_Optionals()
{
var receipt = new Receipt(new uint256(1234), 12345, new Log[] { }, new uint256(12345), new uint160(25), new uint160(24), new uint160(23), true, "SomeResult", "SomeExceptionString", 54321, 1_000_000, null, null) { BlockHash = new uint256(1234) };
this.db.Store(new Receipt[] { receipt });
Receipt retrievedReceipt = this.db.Retrieve(receipt.TransactionHash);
ReceiptSerializationTest.TestStorageReceiptEquality(receipt, retrievedReceipt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ public void Receipt_Serializes_And_Deserializes()
TestStorageSerialize(receipt);

// Test cases where either the sender or contract is null - AKA CALL vs CREATE
receipt = new Receipt(receipt.PostState, receipt.GasUsed, receipt.Logs, new uint256(12345), new uint160(25), new uint160(24), null, true, "Test Result", "Test Error Message", 54321, 1_000_000, "TestMethodName") { BlockHash = new uint256(1234) };
receipt = new Receipt(receipt.PostState, receipt.GasUsed, receipt.Logs, new uint256(12345), new uint160(25), new uint160(24), null, true, "Test Result", "Test Error Message", 54321, 1_000_000, "TestMethodName", 123456) { BlockHash = new uint256(1234) };
TestStorageSerialize(receipt);
receipt = new Receipt(receipt.PostState, receipt.GasUsed, receipt.Logs, new uint256(12345), new uint160(25), null, new uint160(23), true, "Test Result 2", "Test Error Message 2", 54321, 1_000_000) { BlockHash = new uint256(1234) };
TestStorageSerialize(receipt);
}

[Fact]
public void Receipt_With_No_MethodName_Deserializes_Correctly()
public void Receipt_With_No_MethodName_Or_BlockNumber_Deserializes_Correctly()
{
var receipt = new Receipt(new uint256(1234), 12345, new Log[]{}, new uint256(12345), new uint160(25), new uint160(24), null, true, "Test Result", "Test Error Message", 54321, 1_000_000) { BlockHash = new uint256(1234) };

Expand Down Expand Up @@ -141,6 +141,7 @@ public static void TestStorageReceiptEquality(Receipt receipt1, Receipt receipt2
Assert.Equal(receipt1.Success, receipt2.Success);
Assert.Equal(receipt1.ErrorMessage, receipt2.ErrorMessage);
Assert.Equal(receipt1.MethodName, receipt2.MethodName);
Assert.Equal(receipt1.BlockNumber, receipt2.BlockNumber);
}

private static void TestLogsEqual(Log log1, Log log2)
Expand Down
27 changes: 20 additions & 7 deletions src/Stratis.SmartContracts.Core/Receipts/Receipt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ public class Receipt
/// </summary>
public uint256 BlockHash { get; set; }

/// <summary>
/// The height of the block. Nullable for backwards-compatibility with receipt data saved before this field was introduced.
/// </summary>
public ulong? BlockNumber { get; }

/// <summary>
/// Address of the sender of the transaction.
/// </summary>
Expand Down Expand Up @@ -112,8 +117,9 @@ public Receipt(uint256 postState,
string errorMessage,
ulong gasPrice,
ulong amount,
string methodName = null)
: this(postState, gasUsed, logs, BuildBloom(logs), transactionHash, null, @from, to, newContractAddress, success, result, errorMessage, gasPrice, amount, methodName)
string methodName = null,
ulong? blockNumber = null)
: this(postState, gasUsed, logs, BuildBloom(logs), transactionHash, null, @from, to, newContractAddress, success, result, errorMessage, gasPrice, amount, methodName, blockNumber)
{ }

/// <summary>
Expand All @@ -122,7 +128,7 @@ public Receipt(uint256 postState,
public Receipt(uint256 postState,
ulong gasUsed,
Log[] logs)
: this(postState, gasUsed, logs, BuildBloom(logs), null, null, null, null, null, false, null, null, 0, 0, null)
: this(postState, gasUsed, logs, BuildBloom(logs), null, null, null, null, null, false, null, null, 0, 0, null, null)
{ }

/// <summary>
Expand All @@ -133,7 +139,7 @@ private Receipt(
ulong gasUsed,
Log[] logs,
Bloom bloom)
: this(postState, gasUsed, logs, bloom, null, null, null, null, null, false, null, null, 0, 0, null)
: this(postState, gasUsed, logs, bloom, null, null, null, null, null, false, null, null, 0, 0, null, null)
{ }

private Receipt(uint256 postState,
Expand All @@ -150,7 +156,8 @@ private Receipt(uint256 postState,
string errorMessage,
ulong gasPrice,
ulong amount,
string methodName)
string methodName,
ulong? blockNumber)
{
this.PostState = postState;
this.GasPrice = gasPrice;
Expand All @@ -167,6 +174,7 @@ private Receipt(uint256 postState,
this.ErrorMessage = errorMessage;
this.Amount = amount;
this.MethodName = methodName;
this.BlockNumber = blockNumber;
}

/// <summary>
Expand Down Expand Up @@ -246,6 +254,9 @@ public static Receipt FromStorageBytesRlp(byte[] bytes)
// Method name is the 15th item to be added. Existing receipts without this data will throw exceptions without this check.
var hasMethodName = innerList.Count > 14;

// Block number is the 16th item to be added.
var hasBlockNumber = innerList.Count > 15;

var receipt = new Receipt(
new uint256(innerList[0].RLPData),
BitConverter.ToUInt64(innerList[1].RLPData),
Expand All @@ -261,7 +272,8 @@ public static Receipt FromStorageBytesRlp(byte[] bytes)
innerList[11].RLPData != null ? Encoding.UTF8.GetString(innerList[11].RLPData) : null,
BitConverter.ToUInt64(innerList[12].RLPData),
BitConverter.ToUInt64(innerList[13].RLPData),
hasMethodName && innerList[14].RLPData != null ? Encoding.UTF8.GetString(innerList[14].RLPData) : null);
hasMethodName && innerList[14].RLPData != null ? Encoding.UTF8.GetString(innerList[14].RLPData) : null,
hasBlockNumber && innerList[15].RLPData != null ? BitConverter.ToUInt64(innerList[15].RLPData) : (ulong?) null);

return receipt;
}
Expand All @@ -288,7 +300,8 @@ public byte[] ToStorageBytesRlp()
RLP.EncodeElement(Encoding.UTF8.GetBytes(this.ErrorMessage ?? "")),
RLP.EncodeElement(BitConverter.GetBytes(this.GasPrice)),
RLP.EncodeElement(BitConverter.GetBytes(this.Amount)),
RLP.EncodeElement(Encoding.UTF8.GetBytes(this.MethodName ?? ""))
RLP.EncodeElement(Encoding.UTF8.GetBytes(this.MethodName ?? "")),
RLP.EncodeElement(this.BlockNumber.HasValue ? BitConverter.GetBytes(this.BlockNumber.Value) : null)
);
}

Expand Down

0 comments on commit 15822b5

Please sign in to comment.