Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make tx size calculation consistent #3937

Merged
merged 1 commit into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/overlay/FlowControlCapacity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ FlowControlByteCapacity::getCapacityLimits() const
uint64_t
FlowControlByteCapacity::getMsgResourceCount(StellarMessage const& msg) const
{

return static_cast<uint64_t>(xdr::xdr_argpack_size(msg));
return msgBodySize(msg);
}

void
Expand Down Expand Up @@ -204,4 +203,12 @@ FlowControlCapacity::hasOutboundCapacity(StellarMessage const& msg) const
ZoneScoped;
return mOutboundCapacity >= getMsgResourceCount(msg);
}

uint64_t
FlowControlCapacity::msgBodySize(StellarMessage const& msg)
{
return static_cast<uint64_t>(xdr::xdr_size(msg) -
xdr::xdr_size(msg.type()));
}

}
2 changes: 2 additions & 0 deletions src/overlay/FlowControlCapacity.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class FlowControlCapacity

virtual bool canRead() const = 0;

static uint64_t msgBodySize(StellarMessage const& msg);

#ifdef BUILD_TESTS
void
setOutboundCapacity(uint64_t newCapacity)
Expand Down
8 changes: 5 additions & 3 deletions src/overlay/test/OverlayTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ TEST_CASE("flow control byte capacity", "[overlay][flowcontrol]")
// Make tx1 larger than the minimum we can set TX_MAX_SIZE_BYTES to.
tx1.transaction().v0().tx.operations.emplace_back(
getOperationGreaterThanMinMaxSizeBytes());
uint32 txSize = static_cast<uint32>(xdr::xdr_argpack_size(tx1));
uint32 txSize = FlowControlCapacity::msgBodySize(tx1);
REQUIRE(txSize > MinimumSorobanNetworkConfig::TX_MAX_SIZE_BYTES);

VirtualClock clock;
Expand Down Expand Up @@ -276,7 +276,7 @@ TEST_CASE("flow control byte capacity", "[overlay][flowcontrol]")
tx2.transaction().v0().signatures.emplace_back(
SignatureUtils::sign(SecretKey::random(), HashUtils::random()));

uint32 txSize2 = static_cast<uint32>(xdr::xdr_argpack_size(tx2));
uint32 txSize2 = FlowControlCapacity::msgBodySize(tx2);
REQUIRE(txSize2 > MinimumSorobanNetworkConfig::TX_MAX_SIZE_BYTES);
REQUIRE(txSize2 > txSize + 1);

Expand Down Expand Up @@ -910,7 +910,9 @@ TEST_CASE("outbound queue filtering", "[overlay][connections]")
uint32_t limit = node->getLedgerManager().getLastMaxTxSetSizeOps();
StellarMessage msg;
msg.type(TRANSACTION);
auto byteSize = xdr::xdr_argpack_size(msg);
auto byteSize =
peer->getFlowControl()->getCapacityBytes()->getMsgResourceCount(
msg);
SECTION("trim based on message count")
{
for (uint32_t i = 0; i < limit + 10; ++i)
Expand Down
4 changes: 2 additions & 2 deletions src/transactions/TransactionFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ TransactionFrame::getResources() const
if (isSoroban())
{
auto r = sorobanResources();
int64_t txSize = xdr::xdr_size(mEnvelope.v1().tx);
int64_t txSize = xdr::xdr_size(mEnvelope);
int64_t const opCount = 1;

// When doing fee calculation, the rust host will include readWrite
Expand Down Expand Up @@ -735,7 +735,7 @@ TransactionFrame::validateSorobanResources(SorobanNetworkConfig const& config,
return false;
}
}
auto txSize = xdr::xdr_size(mEnvelope.v1().tx);
auto txSize = xdr::xdr_size(mEnvelope);
if (txSize > config.txMaxSizeBytes())
{
pushSimpleDiagnosticError(
Expand Down