public void AddValidBlocksWithForkAllUncommitted() { _store = new ChainStore( new MemoryMappedFileSlim(MemoryMappedFile.CreateNew(null, 10000))); _store.TryOpenBlock(CommittedBlockId.GenesisParent, out var tmpBlock); // U(0) _tmpId1 = tmpBlock.BlockId; _store.TryCommitBlock(tmpBlock.Alias, CommittedBlockId.Genesis, out _); // C(0) _store.TryOpenBlock(CommittedBlockId.Genesis, out var tmp2Block); // C(0) -> U(1) Assert.Equal(tmp2Block.Alias, _1); _tmpId2 = tmp2Block.BlockId; _store.TryCommitBlock(tmp2Block.Alias, _hash1, out _); // C(0) -> C(1) _store.TryOpenBlock(_hash1, out var b1); Assert.Equal(_2, b1.Alias); _tmpId3 = b1.BlockId; // C(0) -> C(1) -> U(2) // Second child for second block _store.TryOpenBlock(_hash1, out b1); Assert.Equal(_2_1, b1.Alias); _tmpId4 = b1.BlockId; // C(0) -> C(1) -> U(2) // \-> U(2-1) }
public OpenBlockResponse OpenBlock(OpenBlockRequest request) { // The request associated to the genesis block does not come with a valid parent. var status = _store.TryOpenBlock(request.ParentId, out var block); switch (status) { case OpenBlockStatus.Success: RefreshAndPropagateLineage(); return(new OpenBlockResponse(ref request.MessageHeader, request.Mask, block.Alias, block.BlockId, _pool)); case OpenBlockStatus.ParentNotFound: return(new OpenBlockResponse(ref request.MessageHeader, Messaging.OpenBlockStatus.ParentNotFound, _pool)); default: throw new NotSupportedException(); } }