Don't return online accounts signatures from GET /blocks/byheight/{height} unless requested using the includesignatures=true query string parameter.

This should fix issue where it would take up to 30 seconds to return for a recent block, and would consume masses of CPU due to having to base58 encode the online accounts signatures. Base58 is very slow and made this API endpoint almost unusable for recent blocks, due to them having untrimmed online accounts signatures.
This commit is contained in:
CalDescent 2021-12-15 16:33:08 +00:00
parent e7fd803d19
commit 3a7da9f13b
3 changed files with 13 additions and 2 deletions

View File

@ -423,17 +423,24 @@ public class BlocksResource {
@ApiErrors({
ApiError.BLOCK_UNKNOWN, ApiError.REPOSITORY_ISSUE
})
public BlockData getByHeight(@PathParam("height") int height) {
public BlockData getByHeight(@PathParam("height") int height,
@QueryParam("includesignatures") Boolean includeSignatures) {
try (final Repository repository = RepositoryManager.getRepository()) {
// Firstly check the database
BlockData blockData = repository.getBlockRepository().fromHeight(height);
if (blockData != null) {
if (includeSignatures == null || includeSignatures == false) {
blockData.setOnlineAccountsSignatures(null);
}
return blockData;
}
// Not found, so try the archive
blockData = repository.getBlockArchiveRepository().fromHeight(height);
if (blockData != null) {
if (includeSignatures == null || includeSignatures == false) {
blockData.setOnlineAccountsSignatures(null);
}
return blockData;
}

View File

@ -204,6 +204,10 @@ public class BlockData implements Serializable {
return this.onlineAccountsSignatures;
}
public void setOnlineAccountsSignatures(byte[] onlineAccountsSignatures) {
this.onlineAccountsSignatures = onlineAccountsSignatures;
}
// JAXB special
@XmlElement(name = "minterAddress")

View File

@ -72,7 +72,7 @@ public class BlockApiTests extends ApiCommon {
@Test
public void testGetBlockByHeight() {
assertNotNull(this.blocksResource.getByHeight(1));
assertNotNull(this.blocksResource.getByHeight(1, true));
}
@Test