ensure that emitted txns don't need to specify network id

This commit is contained in:
Richard Holland
2022-12-21 22:29:18 +00:00
parent 4b2b6a871a
commit 7aa49cdf19

View File

@@ -46,25 +46,32 @@ namespace ripple {
NotTEC
preflight0(PreflightContext const& ctx)
{
uint32_t nodeNID = ctx.app.config().NETWORK_ID;
std::optional<uint32_t> txNID = ctx.tx[~sfNetworkID];
if (nodeNID <= 1024)
if (ctx.tx.isFieldPresent(sfEmitDetails))
{
// legacy networks have ids less than 1024, these networks cannot
// specify NetworkID in txn
if (txNID)
return telNETWORK_ID_MAKES_TX_NON_CANONICAL;
// all emitted transactions are free to pass, do not need network id
}
else
{
// new networks both require the field to be present and require it to
// match
if (!txNID)
return telREQUIRES_NETWORK_ID;
uint32_t nodeNID = ctx.app.config().NETWORK_ID;
std::optional<uint32_t> txNID = ctx.tx[~sfNetworkID];
if (*txNID != nodeNID)
return telWRONG_NETWORK;
if (nodeNID <= 1024)
{
// legacy networks have ids less than 1024, these networks cannot
// specify NetworkID in txn
if (txNID)
return telNETWORK_ID_MAKES_TX_NON_CANONICAL;
}
else
{
// new networks both require the field to be present and require it to
// match
if (!txNID)
return telREQUIRES_NETWORK_ID;
if (*txNID != nodeNID)
return telWRONG_NETWORK;
}
}
auto const txID = ctx.tx.getTransactionID();