Skip to content

Commit

Permalink
Merge pull request #2165 from greymistcube/bump/libplanet-to-3.5.0
Browse files Browse the repository at this point in the history
⬆️ Bump libplanet to 3.5.0
  • Loading branch information
greymistcube authored Oct 5, 2023
2 parents fa91d8e + dfe4bf9 commit ce1cb9b
Show file tree
Hide file tree
Showing 411 changed files with 1,899 additions and 1,735 deletions.
2 changes: 1 addition & 1 deletion .Lib9c.Benchmarks/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ static void Main(string[] args)
var stateStore = new TrieStateStore(stateKeyValueStore);
var actionEvaluator = new ActionEvaluator(
_ => policy.BlockAction,
new BlockChainStates(store, stateStore),
stateStore,
new NCActionLoader());
var chain = new BlockChain(
policy,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ private static void Execute(
{
PreviousState = previousStates,
Signer = agentAddr,
Random = new TestRandom(),
RandomSeed = 0,
Rehearsal = false,
BlockIndex = blockIndex,
});
Expand Down
14 changes: 9 additions & 5 deletions .Lib9c.StateService/Controllers/RemoteEvaluationController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Libplanet.Action;
using Libplanet.Action.State;
using Libplanet.Extensions.ActionEvaluatorCommonComponents;
using Libplanet.Store;
using Microsoft.AspNetCore.Mvc;
using Nekoyume.Action;
using Nekoyume.Action.Loader;
Expand All @@ -14,16 +15,16 @@ namespace Lib9c.StateService.Controllers;
[Route("/evaluation")]
public class RemoteEvaluationController : ControllerBase
{
private readonly IBlockChainStates _blockChainStates;
private readonly IStateStore _stateStore;
private readonly ILogger<RemoteEvaluationController> _logger;
private readonly Codec _codec;

public RemoteEvaluationController(
IBlockChainStates blockChainStates,
IStateStore stateStore,
ILogger<RemoteEvaluationController> logger,
Codec codec)
{
_blockChainStates = blockChainStates;
_stateStore = stateStore;
_logger = logger;
_codec = codec;
}
Expand All @@ -41,11 +42,14 @@ public ActionResult<RemoteEvaluationResponse> GetEvaluation([FromBody] RemoteEva
var actionEvaluator =
new ActionEvaluator(
context => new RewardGold(),
_blockChainStates,
_stateStore,
new NCActionLoader());
return Ok(new RemoteEvaluationResponse
{
Evaluations = actionEvaluator.Evaluate(preEvaluationBlock).Select(ActionEvaluationMarshaller.Serialize)
// FIXME: As a temporary measure, null is used. This does not work properly.
Evaluations = actionEvaluator
.Evaluate(preEvaluationBlock, null)
.Select(ActionEvaluationMarshaller.Serialize)
.ToArray(),
});
}
Expand Down
30 changes: 9 additions & 21 deletions .Lib9c.Tests/Action/ActionContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ namespace Lib9c.Tests.Action
using Libplanet.Action.State;
using Libplanet.Common;
using Libplanet.Crypto;
using Libplanet.Types.Assets;
using Libplanet.Types.Blocks;
using Libplanet.Types.Tx;

public class ActionContext : IActionContext
{
private long _gasUsed;
private IRandom _random = null;

public BlockHash? GenesisHash { get; set; }

Expand All @@ -31,39 +31,27 @@ public class ActionContext : IActionContext

public IAccount PreviousState { get; set; }

public IRandom Random { get; set; }
public int RandomSeed { get; set; }

public HashDigest<SHA256>? PreviousStateRootHash { get; set; }

public bool BlockAction { get; }

public bool IsNativeToken(Currency currency) => false;

public void UseGas(long gas)
{
_gasUsed += gas;
}

public IActionContext GetUnconsumedContext()
{
// Unable to determine if Random has ever been consumed...
return new ActionContext
{
Signer = Signer,
TxId = TxId,
Miner = Miner,
BlockHash = BlockHash,
BlockIndex = BlockIndex,
BlockProtocolVersion = BlockProtocolVersion,
Rehearsal = Rehearsal,
PreviousState = PreviousState,
Random = Random,
PreviousStateRootHash = PreviousStateRootHash,
};
}
public IRandom GetRandom() => _random ?? new TestRandom(RandomSeed);

public long GasUsed() => _gasUsed;

public long GasLimit() => 0;

// FIXME: Temporary measure to allow inheriting already mutated IRandom.
public void SetRandom(IRandom random)
{
_random = random;
}
}
}
38 changes: 19 additions & 19 deletions .Lib9c.Tests/Action/BattleArena10Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public void Execute_InvalidAddressException()
{
PreviousState = _initialStates,
Signer = _agent1Address,
Random = new TestRandom(),
RandomSeed = 0,
}));
}

Expand All @@ -234,7 +234,7 @@ public void Execute_FailedLoadStateException()
{
PreviousState = _initialStates,
Signer = _agent1Address,
Random = new TestRandom(),
RandomSeed = 0,
}));
}

Expand All @@ -258,7 +258,7 @@ public void Execute_NotEnoughClearedStageLevelException()
{
PreviousState = _initialStates,
Signer = _agent4Address,
Random = new TestRandom(),
RandomSeed = 0,
BlockIndex = 1,
}));
}
Expand All @@ -282,7 +282,7 @@ public void Execute_SheetRowNotFoundException()
{
PreviousState = _initialStates,
Signer = _agent1Address,
Random = new TestRandom(),
RandomSeed = 0,
}));
}

Expand All @@ -305,7 +305,7 @@ public void Execute_ThisArenaIsClosedException()
{
PreviousState = _initialStates,
Signer = _agent1Address,
Random = new TestRandom(),
RandomSeed = 0,
BlockIndex = 4480001,
}));
}
Expand All @@ -329,7 +329,7 @@ public void Execute_ArenaParticipantsNotFoundException()
{
PreviousState = _initialStates,
Signer = _agent1Address,
Random = new TestRandom(),
RandomSeed = 0,
BlockIndex = 1,
}));
}
Expand Down Expand Up @@ -391,7 +391,7 @@ public void Execute_AddressNotFoundInArenaParticipantsException(bool excludeMe)
{
PreviousState = previousStates,
Signer = _agent1Address,
Random = new TestRandom(),
RandomSeed = 0,
BlockIndex = 1,
}));
}
Expand Down Expand Up @@ -462,7 +462,7 @@ public void Execute_ValidateScoreDifferenceException(bool isSigner)
BlockIndex = blockIndex,
PreviousState = previousStates,
Signer = _agent1Address,
Random = new TestRandom(),
RandomSeed = 0,
}));
}

Expand Down Expand Up @@ -531,7 +531,7 @@ public void Execute_InsufficientBalanceException()
BlockIndex = blockIndex,
PreviousState = previousStates,
Signer = _agent1Address,
Random = new TestRandom(),
RandomSeed = 0,
}));
}

Expand Down Expand Up @@ -597,7 +597,7 @@ public void Execute_ExceedPlayCountException()
BlockIndex = blockIndex,
PreviousState = previousStates,
Signer = _agent1Address,
Random = new TestRandom(),
RandomSeed = 0,
}));
}

Expand Down Expand Up @@ -677,7 +677,7 @@ public void Execute_ExceedTicketPurchaseLimitException()
BlockIndex = blockIndex,
PreviousState = previousStates,
Signer = _agent1Address,
Random = new TestRandom(),
RandomSeed = 0,
}));
}

Expand Down Expand Up @@ -762,7 +762,7 @@ public void Execute_ExceedTicketPurchaseLimitDuringIntervalException()
BlockIndex = blockIndex,
PreviousState = previousStates,
Signer = _agent1Address,
Random = new TestRandom(),
RandomSeed = 0,
}));
}

Expand Down Expand Up @@ -842,15 +842,15 @@ public void Execute_CoolDownBlockException()
BlockIndex = blockIndex,
PreviousState = previousStates,
Signer = _agent1Address,
Random = new TestRandom(),
RandomSeed = 0,
});

Assert.Throws<CoolDownBlockException>(() => action.Execute(new ActionContext
{
BlockIndex = blockIndex + 1,
PreviousState = nextStates,
Signer = _agent1Address,
Random = new TestRandom(),
RandomSeed = 0,
}));
}

Expand Down Expand Up @@ -919,7 +919,7 @@ public void ExecuteDuplicatedException(int slotIndex, int runeId, int slotIndex2
BlockIndex = 1,
PreviousState = previousStates,
Signer = _agent1Address,
Random = new TestRandom(),
RandomSeed = 0,
});

var action = new BattleArena10
Expand Down Expand Up @@ -972,7 +972,7 @@ public void ExecuteDuplicatedException(int slotIndex, int runeId, int slotIndex2
{
PreviousState = previousStates,
Signer = _agent1Address,
Random = random,
RandomSeed = random.Seed,
Rehearsal = false,
BlockIndex = blockIndex,
}));
Expand Down Expand Up @@ -1059,7 +1059,7 @@ public void Execute_ValidateDuplicateTicketPurchaseException()
BlockIndex = blockIndex,
PreviousState = previousStates,
Signer = _agent1Address,
Random = new TestRandom(),
RandomSeed = 0,
}));
}

Expand Down Expand Up @@ -1204,7 +1204,7 @@ private void Execute(
{
PreviousState = previousStates,
Signer = myAgentAddress,
Random = random,
RandomSeed = random.Seed,
Rehearsal = false,
BlockIndex = blockIndex,
});
Expand Down Expand Up @@ -1309,7 +1309,7 @@ private IAccount JoinArena(
{
PreviousState = states,
Signer = signer,
Random = random,
RandomSeed = random.Seed,
Rehearsal = false,
BlockIndex = blockIndex,
});
Expand Down
Loading

0 comments on commit ce1cb9b

Please sign in to comment.