Skip to content
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
18 changes: 9 additions & 9 deletions EBA/Blockchains/Bitcoin/BitcoinChainAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,18 +153,18 @@ await JsonSerializer.DeserializeAsync<Tx>(stream, cancellationToken: cT)
}

public async Task<List<BlockMetadata>> GetBlockMetadataAsync(
long startBlockHeight,
long endBlockHeight,
long startHeight,
long endHeight,
CancellationToken cT)
{
_logger.LogInformation(
"Getting block metadata for blocks {start:n0} to {end:n0}.",
startBlockHeight, endBlockHeight);
startHeight, endHeight);

var pageSize = 2000;
var pages = new List<long[]>();
for (var i = startBlockHeight; i <= endBlockHeight; i += pageSize)
pages.Add([i, i + pageSize < endBlockHeight ? pageSize : endBlockHeight - i + 1]);
for (var i = startHeight; i <= endHeight; i += pageSize)
pages.Add([i, i + pageSize < endHeight ? pageSize : endHeight - i + 1]);

var blocksMetadata = new ConcurrentBag<BlockMetadata>();

Expand All @@ -191,7 +191,7 @@ await Parallel.ForEachAsync(
});

_logger.LogInformation("Finished Getting block metadata for blocks {start:n0} to {end:n0}.",
startBlockHeight, endBlockHeight);
startHeight, endHeight);

return [.. blocksMetadata];
}
Expand All @@ -216,7 +216,7 @@ await strategy.ExecuteAsync(
},
new Context()
.SetLogger<BitcoinOrchestrator>(_logger)
.SetBlockHeight(height),
.SetHeight(height),
cT);
}
catch (Polly.CircuitBreaker.BrokenCircuitException e)
Expand Down Expand Up @@ -336,7 +336,7 @@ private static async Task ProcessTx(BlockGraph g, Tx tx, BitcoinOptions options,

g.Block.TxoLifecycle.AddOrUpdate(utxo.Id, utxo, (_, oldValue) =>
{
oldValue.SpentInBlockHeight = g.Block.Height;
oldValue.SpentInHeight = g.Block.Height;
return oldValue;
});
}
Expand All @@ -360,7 +360,7 @@ private static async Task ProcessTx(BlockGraph g, Tx tx, BitcoinOptions options,
value: output.Value,
scriptType: output.ScriptPubKey.ScriptType,
isGenerated: false,
createdInBlockHeight: g.Block.Height);
createdInHeight: g.Block.Height);

g.Block.TxoLifecycle.TryAdd(utxo.Id, utxo);
}
Expand Down
6 changes: 3 additions & 3 deletions EBA/Blockchains/Bitcoin/BitcoinOrchestrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ public async Task TraverseAsync(
_logger.LogInformation("Head of the chain is at block {block:n0}.", chainInfo.Blocks);
options.Bitcoin.Traverse.To ??= chainInfo.Blocks;

SetupPersistedQueues(options, out var blockHeightQueue, out var failedBlocksQueue);
SetupPersistedQueues(options, out var heightQueue, out var failedBlocksQueue);

await JsonSerializer<Options>.SerializeAsync(options, options.StatusFile, cT);

if (blockHeightQueue.Count == 0)
if (heightQueue.Count == 0)
{
_logger.LogInformation("No blocks to process.");
return;
Expand All @@ -44,7 +44,7 @@ public async Task TraverseAsync(
try
{
stopwatch.Start();
await TraverseBlocksAsync(options, blockHeightQueue, failedBlocksQueue, cT);
await TraverseBlocksAsync(options, heightQueue, failedBlocksQueue, cT);

stopwatch.Stop();
_logger.LogInformation("Successfully finished traverse in {et}.", stopwatch.Elapsed);
Expand Down
26 changes: 6 additions & 20 deletions EBA/Blockchains/Bitcoin/ChainModel/Utxo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ public class Utxo

public bool IsGenerated { set; get; }

public long CreatedInBlockHeight { get; }
public long CreatedInHeight { get; }

public long? SpentInBlockHeight { set; get; }
public long? SpentInHeight { set; get; }

public Utxo(
string id, string? address, long value, ScriptType scriptType, bool isGenerated,
long createdInBlockHeight,
long? spentInBlockHeight = null)
long createdInHeight,
long? spentInHeight = null)
{
Id = id;
Address = address ?? Id;
Value = value;
ScriptType = scriptType;
IsGenerated = isGenerated;
CreatedInBlockHeight = createdInBlockHeight;
SpentInBlockHeight = spentInBlockHeight;
CreatedInHeight = createdInHeight;
SpentInHeight = spentInHeight;
}

public Utxo(
Expand Down Expand Up @@ -58,18 +58,4 @@ public static string GetTxid(string id)
{
return id.Split('-')[1];
}

public static string GetHeader()
{
return string.Join(
'\t',
"Id",
"Value",
"CreatedInBlockHeights",
"CreatedInBlockHeightsCount",
"SpentInBlockHeights",
"SpentInBlockHeightsCount",
"ScriptType",
"IsGenerated(0=No,1=Yes)");
}
}
2 changes: 1 addition & 1 deletion EBA/Blockchains/Bitcoin/GraphModel/B2BEdge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class B2BEdge(
value: 0,
relation: Kind.Relation,
timestamp: 0,
blockHeight: 0)
height: 0)
{
public static new EdgeKind Kind => new(BlockNode.Kind, BlockNode.Kind, RelationType.Follows);

Expand Down
6 changes: 3 additions & 3 deletions EBA/Blockchains/Bitcoin/GraphModel/B2TEdge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ public class B2TEdge : Edge<BlockNode, TxNode>
public B2TEdge(
BlockNode source, TxNode target,
long value,
uint timestamp, long blockHeight) :
uint timestamp, long height) :
base(
source: source,
target: target,
value: value,
relation: Kind.Relation,
timestamp: timestamp,
blockHeight: blockHeight)
height: height)
{ }

public B2TEdge Update(long value)
{
return new B2TEdge(Source, Target, Value + value, Timestamp, BlockHeight);
return new B2TEdge(Source, Target, Value + value, Timestamp, Height);
}
}
6 changes: 3 additions & 3 deletions EBA/Blockchains/Bitcoin/GraphModel/C2TEdge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ public class C2TEdge(
TxNode target,
long value,
uint timestamp,
long blockHeight)
long height)
: Edge<CoinbaseNode, TxNode>(
source: new CoinbaseNode(),
target: target,
value: value,
relation: RelationType.Mints,
timestamp: timestamp,
blockHeight: blockHeight)
height: height)
{
public new static EdgeKind Kind => new(CoinbaseNode.Kind, TxNode.Kind, RelationType.Mints);

public C2TEdge Update(long value)
{
return new C2TEdge(Target, Value + value, Timestamp, BlockHeight);
return new C2TEdge(Target, Value + value, Timestamp, Height);
}
}
4 changes: 2 additions & 2 deletions EBA/Blockchains/Bitcoin/GraphModel/S2TEdge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class S2TEdge : Edge<ScriptNode, TxNode>
public bool Generated { get; }
public long CreationHeight { get; }

public long SpentHeight { get { return BlockHeight; } }
public long SpentHeight { get { return Height; } }

public S2TEdge(
ScriptNode source,
Expand Down Expand Up @@ -45,7 +45,7 @@ public S2TEdge(
value: value,
relation: Kind.Relation,
timestamp: timestamp,
blockHeight: spentHeight)
height: spentHeight)
{
Txid = txid;
Vout = vout;
Expand Down
6 changes: 3 additions & 3 deletions EBA/Blockchains/Bitcoin/GraphModel/T2SEdge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class T2SEdge : Edge<TxNode, ScriptNode>

public long SpentHeight { get; }

public long CreationHeight => BlockHeight;
public long CreationHeight => Height;

public T2SEdge(
TxNode source,
Expand All @@ -23,7 +23,7 @@ public T2SEdge(
relation: Kind.Relation,
value: output.Value,
timestamp: timestamp,
blockHeight: creationHeight)
height: creationHeight)
{
Vout = output.N;
SpentHeight = spentHeight;
Expand All @@ -43,7 +43,7 @@ public T2SEdge(
relation: Kind.Relation,
value: value,
timestamp: timestamp,
blockHeight: creationHeight)
height: creationHeight)
{
Vout = outputIndex;
SpentHeight = spentHeight;
Expand Down
6 changes: 3 additions & 3 deletions EBA/Blockchains/Bitcoin/GraphModel/T2TEdge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ public class T2TEdge : Edge<TxNode, TxNode>
{
public T2TEdge(
TxNode source, TxNode target,
long value, RelationType type, uint timestamp, long blockHeight) :
long value, RelationType type, uint timestamp, long height) :
base(
source: source,
target: target,
value: value,
relation: type,
timestamp: timestamp,
blockHeight: blockHeight)
height: height)
{ }

public static EdgeKind KindTransfers => new(TxNode.Kind, TxNode.Kind, RelationType.Transfers);
Expand Down Expand Up @@ -40,6 +40,6 @@ public static T2TEdge Update(T2TEdge oldEdge, T2TEdge newEdge)
newEdge.Value,
newEdge.Relation,
newEdge.Timestamp,
newEdge.BlockHeight);
newEdge.Height);
}
}
8 changes: 4 additions & 4 deletions EBA/Blockchains/Bitcoin/Utilities/TraverseFinalizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public async Task UpdatePostTraverse(CancellationToken ct)
_logger.LogInformation("Deserialized {n} batches from {filename}.", batches.Count, _options.Bitcoin.MapSpends.BatchesFilename);

_processStep = "[1/4] Block-to-batch mapping:";
GetBlockHeightToBatchMapping(_options, batches, out var blockToBatch, out var blockNodes);
GetHeightToBatchMapping(_options, batches, out var blockToBatch, out var blockNodes);

_processStep = "[2/4] Collecting Txo spending:";
await CreatePerBatchSpentUtxo(batches, blockToBatch, ct);
Expand All @@ -33,7 +33,7 @@ public async Task UpdatePostTraverse(CancellationToken ct)
await SetSupplyAmount(batches, blockNodes, ct);
}

private void GetBlockHeightToBatchMapping(
private void GetHeightToBatchMapping(
Options options,
List<Batch> batches,
out Dictionary<long, Batch> blockToBatch,
Expand Down Expand Up @@ -73,7 +73,7 @@ private static string GetSpentTxoFilename(Batch batch)
batch.FilenamePrefix + "_spent_utxos.csv");
}

private async Task CreatePerBatchSpentUtxo(List<Batch> batches, Dictionary<long, Batch> blockHeightToBatchMapping, CancellationToken ct)
private async Task CreatePerBatchSpentUtxo(List<Batch> batches, Dictionary<long, Batch> heightToBatchMapping, CancellationToken ct)
{
_logger.LogInformation("{s} Creating per-batch spent Txo files; these are temporary files and can be deleted after process ends.", _processStep);

Expand All @@ -95,7 +95,7 @@ private async Task CreatePerBatchSpentUtxo(List<Batch> batches, Dictionary<long,

await foreach (var cols in IElementCodec.ReadCsvAsync(batch.GetFilename(S2TEdge.Kind), ct))
{
var writer = blockToWriterMapping[blockHeightToBatchMapping[creationHeightParser(cols)].Name];
var writer = blockToWriterMapping[heightToBatchMapping[creationHeightParser(cols)].Name];
writer.WriteLine(string.Join(Options.CsvDelimiter,
txidParser(cols), // preout txid
voutParser(cols), // preout vout
Expand Down
6 changes: 3 additions & 3 deletions EBA/Graph/Bitcoin/Descriptors/B2BEdgeDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ public class B2BEdgeDescriptor : IElementDescriptor<B2BEdge>
public static ElementMapper<B2BEdge> StaticMapper => _mapper;
private static readonly ElementMapper<B2BEdge> _mapper = new(
new MappingBuilder<B2BEdge>()
.MapSourceId(BlockNodeDescriptor.IdSpace, e => e.BlockHeight)
.MapTargetId(BlockNodeDescriptor.IdSpace, e => e.BlockHeight)
.MapSourceId(BlockNodeDescriptor.IdSpace, e => e.Height)
.MapTargetId(BlockNodeDescriptor.IdSpace, e => e.Height)
.MapEdgeType(e => e.Relation)
.ToArray());

Expand All @@ -25,7 +25,7 @@ public string[] Neo4jSeedingOverride
return
[
$"MATCH (target:Block), (source:Block) " +
$"\r\nWHERE target.{nameof(B2BEdge.BlockHeight)} + 1 = source.{nameof(B2BEdge.BlockHeight)} " +
$"\r\nWHERE target.{nameof(B2BEdge.Height)} + 1 = source.{nameof(B2BEdge.Height)} " +
$"\r\nMERGE (target)-[:{RelationType.Follows}]->(source)"
];
}
Expand Down
4 changes: 2 additions & 2 deletions EBA/Graph/Bitcoin/Descriptors/B2TEdgeDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class B2TEdgeDescriptor : IElementDescriptor<B2TEdge>
.MapSourceId(BlockNodeDescriptor.IdSpace, e => e.Source.BlockMetadata.Height)
.MapTargetId(TxNodeDescriptor.IdSpace, e => e.Target.Txid)
.Map(e => e.Value)
.Map(e => e.BlockHeight)
.Map(e => e.Height)
.MapEdgeType(e => e.Relation)
.ToArray());

Expand All @@ -24,7 +24,7 @@ public static B2TEdge Deserialize(
source: source,
target: target,
timestamp: 0,
blockHeight: _mapper.GetValue(e => e.BlockHeight, props),
height: _mapper.GetValue(e => e.Height, props),
value: _mapper.GetValue(e => e.Value, props));
}
}
4 changes: 2 additions & 2 deletions EBA/Graph/Bitcoin/Descriptors/C2TEdgeDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class C2TEdgeDescriptor : IElementDescriptor<C2TEdge>
.MapSourceId(CoinbaseNode.Kind.ToString(), _ => CoinbaseNode.Kind)
.MapTargetId(TxNodeDescriptor.IdSpace, e => e.Target.Txid)
.Map(e => e.Value)
.Map(e => e.BlockHeight)
.Map(e => e.Height)
.MapEdgeType(e => e.Relation)
.ToArray());

Expand All @@ -24,6 +24,6 @@ public static C2TEdge Deserialize(
target: target,
value: _mapper.GetValue(e => e.Value, props),
timestamp: 0,
blockHeight: _mapper.GetValue(e => e.BlockHeight, props));
height: _mapper.GetValue(e => e.Height, props));
}
}
4 changes: 2 additions & 2 deletions EBA/Graph/Bitcoin/Descriptors/T2TEdgeDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class T2TEdgeDescriptor : IElementDescriptor<T2TEdge>
.MapSourceId(TxNodeDescriptor.IdSpace, e => e.Source.Txid)
.MapTargetId(TxNodeDescriptor.IdSpace, e => e.Target.Txid)
.Map(e => e.Value)
.Map(e => e.BlockHeight)
.Map(e => e.Height)
.MapEdgeType(e => e.Relation)
.ToArray());

Expand All @@ -25,7 +25,7 @@ public static T2TEdge Deserialize(
source: source,
target: target,
timestamp: 0,
blockHeight: _mapper.GetValue(e => e.BlockHeight, props),
height: _mapper.GetValue(e => e.Height, props),
value: _mapper.GetValue(e => e.Value, props),
type: Enum.Parse<RelationType>(relationType, ignoreCase: true));
}
Expand Down
Loading