class PendingBlocks {

  public boolean registerPendingBlock(final Block pendingBlock) {
    final Block previousValue =
        this.pendingBlocks.putIfAbsent(pendingBlock.getHash(), pendingBlock);
    if (previousValue != null) {
      return false;
    }

    pendingBlocksByParentHash
        .computeIfAbsent(
            pendingBlock.getHeader().getParentHash(),
            h -> {
              final Set<Hash> set = newSetFromMap(new ConcurrentHashMap<>());
              // Go ahead and add our value at construction, so that we don't set an empty set which
              // could be removed in deregisterPendingBlock
              set.add(pendingBlock.getHash());
              return set;
            })
        .add(pendingBlock.getHash());

    return true;
  }

}