Skip to content

Commit

Permalink
Bugfix/missing account updates fix (#1095)
Browse files Browse the repository at this point in the history
* adding jakartanet metadata

* fixed wording
  • Loading branch information
piotrkosecki authored Jun 17, 2022
1 parent 4f728d0 commit 42b1148
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,19 @@ object TezosTypes {
voting_period_kind: Option[VotingPeriod.Kind],
voting_period_info: Option[VotingPeriodInfo],
level: Option[BlockHeaderMetadataLevel],
level_info: Option[BlockHeaderMetadataLevelInfo]
level_info: Option[BlockHeaderMetadataLevelInfo],
implicit_operations_results: Option[List[ImplicitOperationResults]]
) extends BlockMetadata

final case class ImplicitOperationResults(
kind: String,
storage: Option[Micheline],
balance_updates: List[OperationMetadata.BalanceUpdate],
consumed_gas: PositiveBigNumber,
consumed_miligas: PositiveBigNumber,
storage_size: PositiveBigNumber
)

final case class BlockHeaderMetadataLevel(
level: BlockLevel,
level_position: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ object VotingOperations {

/* Used to classify blocks by voting periods via metadata */
private def votingPeriodIn(accept: VotingPeriod.ValueSet, metadata: BlockMetadata): Boolean = metadata match {
case BlockHeaderMetadata(_, _, _, _, Some(voting_period_kind), _, _, _) =>
case BlockHeaderMetadata(_, _, _, _, Some(voting_period_kind), _, _, _, _) =>
accept(voting_period_kind)
case BlockHeaderMetadata(_, _, _, _, _, Some(voting_period_info), _, _) =>
case BlockHeaderMetadata(_, _, _, _, _, Some(voting_period_info), _, _, _) =>
accept(voting_period_info.voting_period.kind)
case GenesisMetadata =>
false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ object BlockBalances {
Map(
BlockTagged.fromBlockData(data, BLOCK_SOURCE) -> (data.metadata match {
case GenesisMetadata => List.empty
case BlockHeaderMetadata(balance_updates, _, _, _, _, _, _, _) => balance_updates
case BlockHeaderMetadata(balance_updates, _, _, _, _, _, _, _, maybeImplicitOperationResults) =>
balance_updates ++ maybeImplicitOperationResults.toList.flatten.flatMap(_.balance_updates)
})
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ private[tezos] object TezosJsonDecoders {
implicit val metadataLevelDecoder: Decoder[BlockHeaderMetadataLevel] = deriveConfiguredDecoder
val blockMetadataDecoder: Decoder[BlockHeaderMetadata] = deriveConfiguredDecoder
implicit val votingPeriodInfoDecoder: Decoder[VotingPeriodInfo] = deriveConfiguredDecoder
implicit val implicitOperationResultsDecoder: Decoder[ImplicitOperationResults] = deriveConfiguredDecoder
implicit val votingPeriodObjectDecoder: Decoder[VotingPeriodObject] = deriveConfiguredDecoder
implicit val blockHeaderMetadataLevelInfoDecoder: Decoder[BlockHeaderMetadataLevelInfo] = deriveConfiguredDecoder
implicit val metadataDecoder: Decoder[BlockMetadata] = blockMetadataDecoder.widen or genesisMetadataDecoder.widen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,12 @@ private[tezos] class TezosNodeOperator(
id <- balanceUpdate.contract.map(_.id).toList ::: balanceUpdate.delegate.map(_.value).toList
} yield makeAccountId(id)

def extractAccountIdsFromImplicitOpResults(blockData: BlockData): List[AccountId] =
for {
blockHeaderMetadata <- discardGenesis(blockData.metadata).toList
id <- blockHeaderMetadata.implicit_operations_results.toList.flatten.flatMap(_.balance_updates.flatMap(_.contract.toList))
} yield makeAccountId(id.id)

//Gets blocks data for the requested offsets and associates the operations and account hashes available involved in said operations
//Special care is taken for the genesis block (level = 0) that doesn't have operations defined, we use empty data for it
/* implicitly uses:
Expand All @@ -745,7 +751,7 @@ private[tezos] class TezosNodeOperator(
fetchedBlocksData.map { case (offset, md) =>
val (ops, accs) = if (isGenesis(md)) (List.empty, List.empty) else operationalDataMap(md.hash)
val votes = proposalsMap.getOrElse(md.hash, CurrentVotes.empty)
(parseMichelsonScripts(Block(md, ops, votes)), (accs ::: extractAccountIds(md)).distinct)
(parseMichelsonScripts(Block(md, ops, votes)), (accs ::: extractAccountIds(md) ::: extractAccountIdsFromImplicitOpResults(md)).distinct)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class BakingAndEndorsingRightsProcessor(
data.metadata match {
case TezosTypes.GenesisMetadata =>
RightsFetchKey(data.hash, None, None)
case BlockHeaderMetadata(_, _, _, _, _, voting_period_info, level, level_info) =>
case BlockHeaderMetadata(_, _, _, _, _, voting_period_info, level, level_info, _) =>
RightsFetchKey(
data.hash,
level.map(_.cycle).orElse(level_info.map(_.cycle)),
Expand Down

0 comments on commit 42b1148

Please sign in to comment.