Skip to content

Commit

Permalink
Merge pull request #403 from moreal/txpoller-parallel
Browse files Browse the repository at this point in the history
Huge work; Run TxPoller in parallel
  • Loading branch information
moreal authored Oct 23, 2024
2 parents d0ab4e7 + 761a31b commit 3515b3e
Show file tree
Hide file tree
Showing 112 changed files with 1,534 additions and 1,623 deletions.
1 change: 0 additions & 1 deletion Mimir.MongoDB.Tests/Bson/ActionPointDocumentTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Mimir.MongoDB.Bson;
using Mimir.MongoDB.Json.Extensions;

namespace Mimir.MongoDB.Tests.Bson;

Expand Down
1 change: 0 additions & 1 deletion Mimir.MongoDB.Tests/Bson/AgentDocumentTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Lib9c.Models.States;
using Mimir.MongoDB.Bson;
using Mimir.MongoDB.Json.Extensions;
using Mimir.MongoDB.Tests.TestDatas;

namespace Mimir.MongoDB.Tests.Bson;
Expand Down
1 change: 0 additions & 1 deletion Mimir.MongoDB.Tests/Bson/AllRuneDocumentTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Lib9c.Models.States;
using Mimir.MongoDB.Bson;
using Mimir.MongoDB.Json.Extensions;
using Mimir.MongoDB.Tests.TestDatas;

namespace Mimir.MongoDB.Tests.Bson;
Expand Down
1 change: 0 additions & 1 deletion Mimir.MongoDB.Tests/Bson/ArenaDocumentTest.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Lib9c.Models.Arena;
using Lib9c.Models.States;
using Mimir.MongoDB.Bson;
using Mimir.MongoDB.Json.Extensions;
using Mimir.MongoDB.Tests.TestDatas;

namespace Mimir.MongoDB.Tests.Bson;
Expand Down
1 change: 0 additions & 1 deletion Mimir.MongoDB.Tests/Bson/AvatarDocumentTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Lib9c.Models.States;
using Mimir.MongoDB.Bson;
using Mimir.MongoDB.Json.Extensions;
using Mimir.MongoDB.Tests.TestDatas;

namespace Mimir.MongoDB.Tests.Bson;
Expand Down
1 change: 0 additions & 1 deletion Mimir.MongoDB.Tests/Bson/BalanceDocumentTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Mimir.MongoDB.Bson;
using Mimir.MongoDB.Json.Extensions;

namespace Mimir.MongoDB.Tests.Bson;

Expand Down
1 change: 0 additions & 1 deletion Mimir.MongoDB.Tests/Bson/CollectionDocumentTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Lib9c.Models.States;
using Mimir.MongoDB.Bson;
using Mimir.MongoDB.Json.Extensions;
using Mimir.MongoDB.Tests.TestDatas;

namespace Mimir.MongoDB.Tests.Bson;
Expand Down
1 change: 0 additions & 1 deletion Mimir.MongoDB.Tests/Bson/InventoryDocumentTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Mimir.MongoDB.Bson;
using Mimir.MongoDB.Json.Extensions;
using Mimir.MongoDB.Tests.TestDatas;
using Inventory = Lib9c.Models.Items.Inventory;

Expand Down
1 change: 0 additions & 1 deletion Mimir.MongoDB.Tests/Bson/ItemSlotDocumentTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Lib9c.Models.States;
using Mimir.MongoDB.Bson;
using Mimir.MongoDB.Json.Extensions;
using Mimir.MongoDB.Tests.TestDatas;

namespace Mimir.MongoDB.Tests.Bson;
Expand Down
1 change: 0 additions & 1 deletion Mimir.MongoDB.Tests/Bson/PetStateDocumentTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Lib9c.Models.States;
using Mimir.MongoDB.Bson;
using Mimir.MongoDB.Json.Extensions;
using Mimir.MongoDB.Tests.TestDatas;

namespace Mimir.MongoDB.Tests.Bson;
Expand Down
1 change: 0 additions & 1 deletion Mimir.MongoDB.Tests/Bson/PledgeDocumentTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Mimir.MongoDB.Bson;
using Mimir.MongoDB.Json.Extensions;

namespace Mimir.MongoDB.Tests.Bson;

Expand Down
1 change: 0 additions & 1 deletion Mimir.MongoDB.Tests/Bson/ProductDocument.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Lib9c.Models.Market;
using Mimir.MongoDB.Bson;
using Mimir.MongoDB.Json.Extensions;
using Mimir.MongoDB.Tests.TestDatas;
using ItemProduct = Lib9c.Models.Market.ItemProduct;

Expand Down
1 change: 0 additions & 1 deletion Mimir.MongoDB.Tests/Bson/ProductsStateDocument.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Lib9c.Models.Market;
using Mimir.MongoDB.Bson;
using Mimir.MongoDB.Json.Extensions;
using Mimir.MongoDB.Tests.TestDatas;

namespace Mimir.MongoDB.Tests.Bson;
Expand Down
1 change: 0 additions & 1 deletion Mimir.MongoDB.Tests/Bson/RaiderStateDocumentTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Lib9c.Models.States;
using Mimir.MongoDB.Bson;
using Mimir.MongoDB.Json.Extensions;
using Mimir.MongoDB.Tests.TestDatas;

namespace Mimir.MongoDB.Tests.Bson;
Expand Down
1 change: 0 additions & 1 deletion Mimir.MongoDB.Tests/Bson/RuneSlotDocumentTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Lib9c.Models.States;
using Mimir.MongoDB.Bson;
using Mimir.MongoDB.Json.Extensions;
using Mimir.MongoDB.Tests.TestDatas;

namespace Mimir.MongoDB.Tests.Bson;
Expand Down
1 change: 0 additions & 1 deletion Mimir.MongoDB.Tests/Bson/StakeDocumentTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Lib9c.Models.States;
using Mimir.MongoDB.Bson;
using Mimir.MongoDB.Json.Extensions;
using Mimir.MongoDB.Tests.TestDatas;

namespace Mimir.MongoDB.Tests.Bson;
Expand Down
1 change: 0 additions & 1 deletion Mimir.MongoDB.Tests/Bson/WorldBossStateDocumentTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Lib9c.Models.States;
using Mimir.MongoDB.Bson;
using Mimir.MongoDB.Json.Extensions;
using Mimir.MongoDB.Tests.TestDatas;

namespace Mimir.MongoDB.Tests.Bson;
Expand Down
1 change: 0 additions & 1 deletion Mimir.MongoDB.Tests/Bson/WorldInformationDocumentTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Lib9c.Models.States;
using Mimir.MongoDB.Bson;
using Mimir.MongoDB.Json.Extensions;
using Mimir.MongoDB.Tests.TestDatas;

namespace Mimir.MongoDB.Tests.Bson;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
using Mimir.MongoDB.Bson;
using Mimir.MongoDB.Json.Converters;
using MongoDB.Bson;
using MongoDB.Driver;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace Mimir.MongoDB.Json.Extensions;
namespace Mimir.MongoDB.Bson;

public static class MimirBsonDocumentExtensions
{
public static WriteModel<BsonDocument> ToUpdateOneModel(this MimirBsonDocument document)
{
var json = document.ToJson();
var bsonDocument = BsonDocument.Parse(json);
var filter = Builders<BsonDocument>.Filter.Eq("Address", document.Address.ToHex());
var update = new BsonDocument("$set", bsonDocument);
var upsertOne = new UpdateOneModel<BsonDocument>(filter, update) { IsUpsert = true };

return upsertOne;
}

public static readonly JsonSerializerSettings JsonSerializerSettings = new()
{
Formatting = Formatting.None,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Security.Cryptography;
using Lib9c.Models.Items;
using Libplanet.Common;
using Mimir.MongoDB.Json.Extensions;
using MongoDB.Bson;
using MongoDB.Bson.Serialization;
using MongoDB.Bson.Serialization.Serializers;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Security.Cryptography;
using Lib9c.Models.Items;
using Libplanet.Common;
using Mimir.MongoDB.Json.Extensions;
using MongoDB.Bson;
using MongoDB.Bson.Serialization;
using MongoDB.Bson.Serialization.Serializers;
Expand Down
11 changes: 2 additions & 9 deletions Mimir.MongoDB/CollectionNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ static CollectionNames()
RegisterCollectionAndStateMappings();
}

private static Address GetAccountAddress(Currency currency) => new(currency.Hash.ToByteArray());
public static Address GetAccountAddress(Currency currency) => new(currency.Hash.ToByteArray());

/// <summary>
/// Register MongoDB collections for various related address.
Expand Down Expand Up @@ -127,14 +127,7 @@ private static void RegisterCollectionAndStateMappings()

public static string GetCollectionName<T>()
{
if (!CollectionAndStateTypeMappings.TryGetValue(typeof(T), out var collectionName))
{
throw new InvalidOperationException(
$"No collection mapping found for state type: {typeof(T).FullName}"
);
}

return collectionName;
return GetCollectionName(typeof(T));
}

public static string GetCollectionName(Type type)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Lib9c.Models.Items;
using Mimir.MongoDB.Json.Extensions;
using Mimir.MongoDB.Bson;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

Expand Down
1 change: 1 addition & 0 deletions Mimir.MongoDB/Mimir.MongoDB.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<PackageReference Include="Lib9c" Version="1.18.0"/>
<PackageReference Include="Libplanet" Version="5.3.0-alpha.3" />
<PackageReference Include="MongoDB.Bson" Version="2.27.0" />
<PackageReference Include="MongoDB.Driver" Version="2.27.0" />
<PackageReference Include="MongoDB.Driver.GridFS" Version="2.27.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3"/>
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
using Bencodex.Types;
using Libplanet.Crypto;
using Mimir.MongoDB.Bson;
using Mimir.Worker.Handler;
using Mimir.Worker.StateDocumentConverter;

namespace Mimir.Worker.Tests.Handler;
namespace Mimir.Worker.Tests.StateDocumentConverter;

public class ActionPointStateHandlerTests
public class ActionPointStateDocumentConverterTests
{
private readonly ActionPointStateHandler _handler = new();
private readonly ActionPointStateDocumentConverter _converter = new();

[Theory]
[InlineData(0)]
[InlineData(120)]
public void ConvertToStateData(int actionPoint)
{
var address = new PrivateKey().Address;
var context = new StateDiffContext
var context = new AddressStatePair
{
Address = address,
RawState = new Integer(actionPoint),
};
var doc = _handler.ConvertToDocument(context);
var doc = _converter.ConvertToDocument(context);

Assert.IsType<ActionPointDocument>(doc);
var dataState = (ActionPointDocument)doc;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using Lib9c.Models.States;
using Libplanet.Crypto;
using Mimir.MongoDB.Bson;
using Mimir.Worker.Handler;
using Mimir.Worker.StateDocumentConverter;

namespace Mimir.Worker.Tests.Handler;
namespace Mimir.Worker.Tests.StateDocumentConverter;

public class AgentStateHandlerTests
public class AgentStateDocumentConverterTests
{
private readonly AgentStateHandler _handler = new();
private readonly AgentStateDocumentConverter _converter = new();

[Theory]
[InlineData(0)]
Expand All @@ -22,12 +21,12 @@ public void ConvertToStateData(int avatarCount)
}

var bencoded = state.SerializeList();
var context = new StateDiffContext
var context = new AddressStatePair
{
Address = address,
RawState = bencoded,
};
var doc = _handler.ConvertToDocument(context);
var doc = _converter.ConvertToDocument(context);
Assert.IsType<AgentDocument>(doc);
var agentDoc = (AgentDocument)doc;
Assert.Equal(address, agentDoc.Address);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
using Libplanet.Crypto;
using Mimir.MongoDB.Bson;
using Mimir.Worker.Handler;
using Mimir.Worker.StateDocumentConverter;

namespace Mimir.Worker.Tests.Handler;
namespace Mimir.Worker.Tests.StateDocumentConverter;

public class AllCombinationSlotStateHandlerTests
public class AllCombinationSlotStateDocumentConverterTests
{
private readonly AllCombinationSlotStateHandler _handler = new();
private readonly AllCombinationSlotStateDocumentConverter _converter = new();

[Fact]
public void ConvertToStateData()
{
var address = new PrivateKey().Address;
var state = new Nekoyume.Model.State.AllCombinationSlotState();
var bencoded = state.Serialize();
var context = new StateDiffContext
var context = new AddressStatePair
{
Address = address,
RawState = bencoded,
};
var doc = _handler.ConvertToDocument(context);
var doc = _converter.ConvertToDocument(context);
Assert.IsType<AllCombinationSlotStateDocument>(doc);
var combinationSlotStateDoc = (AllCombinationSlotStateDocument)doc;
Assert.Equal(address, combinationSlotStateDoc.Address);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using Libplanet.Crypto;
using Mimir.MongoDB.Bson;
using Mimir.Worker.Handler;
using Mimir.Worker.StateDocumentConverter;

namespace Mimir.Worker.Tests.Handler;
namespace Mimir.Worker.Tests.StateDocumentConverter;

public class AllRuneStateHandlerTests
public class AllRuneStateDocumentConverterTests
{
private readonly AllRuneStateHandler _handler = new();
private readonly AllRuneStateDocumentConverter _converter = new();

[Theory]
[InlineData(0, 0)]
Expand All @@ -16,12 +16,12 @@ public void ConvertToStateData(int runeId, int level)
var address = new PrivateKey().Address;
var state = new Nekoyume.Model.State.AllRuneState(runeId, level);
var bencoded = state.Serialize();
var context = new StateDiffContext
var context = new AddressStatePair
{
Address = address,
RawState = bencoded,
};
var doc = _handler.ConvertToDocument(context);
var doc = _converter.ConvertToDocument(context);
Assert.IsType<AllRuneDocument>(doc);
var allRuneDoc = (AllRuneDocument)doc;
Assert.Equal(address, allRuneDoc.Address);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
using Bencodex;
using Libplanet.Crypto;
using Mimir.MongoDB.Bson;
using Mimir.Worker.Handler;
using Mimir.Worker.StateDocumentConverter;

namespace Mimir.Worker.Tests.Handler;
namespace Mimir.Worker.Tests.StateDocumentConverter;

public class AvatarStateHandlerTests
public class AvatarStateDocumentConverterTests
{
private readonly Codec Codec = new();
private readonly AvatarStateHandler _handler = new();
private readonly AvatarStateDocumentConverter _converter = new();

[Fact]
public void ConvertToStateData()
{
var address = new Address("4b4eccd6c6b17fe8d4312a0d2fadb0c93ad5a7ba");
var rawState = TestHelpers.ReadTestData("avatarState.txt");
var context = new StateDiffContext()
var context = new AddressStatePair()
{
Address = address,
RawState = Codec.Decode(Convert.FromHexString(rawState)),
};
var state = _handler.ConvertToDocument(context);
var state = _converter.ConvertToDocument(context);

Assert.IsType<AvatarDocument>(state);
}
Expand Down
Loading

0 comments on commit 3515b3e

Please sign in to comment.