diff --git a/DOCKER/Dockerfile b/DOCKER/Dockerfile index d5ef8b85..1a92c319 100644 --- a/DOCKER/Dockerfile +++ b/DOCKER/Dockerfile @@ -10,9 +10,6 @@ COPY DOCKER/bin /app/bin RUN apt-get update && apt-get install -y curl inotify-tools libgflags-dev libsnappy-dev zlib1g-dev libbz2-dev libzstd-dev libc6-dev libicu-dev libgflags-dev libsnappy-dev zlib1g-dev libbz2-dev libzstd-dev librocksdb-dev libc6-dev libsnappy-dev libicu-dev screen bash vim net-tools ca-certificates openssl libssl-dev nano -#RUN curl -sSL https://dot.net/v1/dotnet-install.sh | /bin/bash /dev/stdin -Channel 6.0 -Runtime dotnet -InstallDir /usr/share/dotnet \ -# && ln -s /usr/share/dotnet/dotnet /usr/bin/dotnet - EXPOSE 7077 7078 7079 7080 26056 26156 26256 26356 26057 26157 26257 26357 RUN chmod +x /app/wrapper.sh diff --git a/DOCKER/DockerfileTestnet b/DOCKER/DockerfileTestnet index 225add70..21d39c31 100644 --- a/DOCKER/DockerfileTestnet +++ b/DOCKER/DockerfileTestnet @@ -9,7 +9,8 @@ COPY DOCKER/bin /app/bin RUN apt-get update; apt-get install -y inotify-tools libgflags-dev libsnappy-dev zlib1g-dev libbz2-dev libzstd-dev libc6-dev libicu-dev libgflags-dev libsnappy-dev zlib1g-dev libbz2-dev libzstd-dev librocksdb-dev libc6-dev libsnappy-dev libicu-dev screen bash vim net-tools ca-certificates openssl libssl-dev libgdiplus libx11-dev nano -EXPOSE 7077 7078 7079 7080 26056 26156 26256 26356 26057 26157 26257 26357 +#EXPOSE 7077 7078 7079 7080 26056 26156 26256 26356 26057 26157 26257 26357 +EXPOSE 7078 7079 7080 26156 26256 26356 26157 26257 26357 RUN chmod +x /app/wrapper-testnet.sh ENTRYPOINT ["/app/wrapper-testnet.sh"] diff --git a/DOCKER/DockerfileTestnetDebug b/DOCKER/DockerfileTestnetDebug new file mode 100644 index 00000000..18490825 --- /dev/null +++ b/DOCKER/DockerfileTestnetDebug @@ -0,0 +1,15 @@ +#--platform=linux/x86_64 +FROM mcr.microsoft.com/dotnet/aspnet:6.0 as runtime +WORKDIR /app + +# Copy everything +COPY DOCKER/wrapper-testnet-debug.sh /app/wrapper-testnet-debug.sh +COPY DOCKER/bin /app/bin + +RUN apt-get update; apt-get install -y libc6-dev libsnappy-dev libicu-dev screen bash vim net-tools ca-certificates openssl libssl-dev librocksdb-dev nano + +#EXPOSE 7077 7078 7079 7080 26056 26156 26256 26356 26057 26157 26257 26357 +EXPOSE 7078 7079 7080 26156 26256 26356 26157 26257 26357 + +RUN chmod +x /app/wrapper-testnet-debug.sh +ENTRYPOINT ["/app/wrapper-testnet-debug.sh"] diff --git a/DOCKER/wrapper-testnet-debug.sh b/DOCKER/wrapper-testnet-debug.sh new file mode 100644 index 00000000..c8b10a01 --- /dev/null +++ b/DOCKER/wrapper-testnet-debug.sh @@ -0,0 +1,34 @@ +#!/bin/bash +# reset all nodes +TROOT=/app/testnet +DIR="/app/testnet/node0/data/" + +if [ -d "$DIR" ]; then + # Take action if $DIR exists. # + echo "Tendermint run..." +else + TMHOME=/app/testnet/node0 /app/bin/tendermint unsafe-reset-all + TMHOME=/app/testnet/node1 /app/bin/tendermint unsafe-reset-all + TMHOME=/app/testnet/node2 /app/bin/tendermint unsafe-reset-all + TMHOME=/app/testnet/node3 /app/bin/tendermint unsafe-reset-all +fi + +# Clear old screens +screen -ls | grep 'node' | grep '(Detached)' | awk '{print $1}' | xargs -I % -t screen -X -S % quit +screen -wipe +#pkill -f "tendermint" + +# Move config files +cp $TROOT/node0/config_node0.json $TROOT/node0/publish/config.json +cp $TROOT/node1/config_node1.json $TROOT/node1/publish/config.json +cp $TROOT/node2/config_node2.json $TROOT/node2/publish/config.json +cp $TROOT/node3/config_node3.json $TROOT/node3/publish/config.json + +# start all tendermint sessions +#screen -S node0p -dm bash -c 'cd /app/testnet/node0/publish/; dotnet phantasma-node.dll; exec sh' +screen -S node1p -dm bash -c 'cd /app/testnet/node1/publish/; dotnet phantasma-node.dll; exec sh' +screen -S node2p -dm bash -c 'cd /app/testnet/node2/publish/; dotnet phantasma-node.dll; exec sh' +screen -S node3p -dm bash -c 'cd /app/testnet/node3/publish/; dotnet phantasma-node.dll; exec sh' + +#screen -rd node0p +/bin/bash \ No newline at end of file diff --git a/NodeExample/runTenderminNode.sh b/NodeExample/runTenderminNode.sh old mode 100644 new mode 100755 index 295f2d80..3ad5c1f8 --- a/NodeExample/runTenderminNode.sh +++ b/NodeExample/runTenderminNode.sh @@ -3,17 +3,19 @@ TROOT=`pwd` NODENAME="node" TMHOME=$TROOT/$NODENAME/ -TENDERMINTPATH=./tendermint/tendermint # Change this to `./tendermint/tendermint - +TENDERMINTPATH=./bin/tendermint # Change this to `./tendermint/tendermint +echo $TMHOME # Setup node if not setuped previously DIR="./node/data/" if [ -d "$DIR" ]; then echo "Node already configured" else - $TENDERMINTPATH --home "$(pwd)/$NODENAME/" init + $TENDERMINTPATH --home "$TMHOME" unsafe-reset-all + #$TENDERMINTPATH --home "$TMHOME" init fi # start tendermint # --proxy_app "tcp://127.0.0.1:26558" is used to setup the proxy_app (Phantasma.Node) ip address / port that is going to list to # --p2p.seeds "node_ID@ip_address:node_port" -> can be used as a parameter to provide the seeds other way is going into the config.toml file. -$TENDERMINTPATH --home "$(pwd)/$NODENAME/" node \ No newline at end of file +$TENDERMINTPATH --home "$TMHOME" node +echo $TENDERMINTPATH --home "$TMHOME" node \ No newline at end of file diff --git a/Phantasma.Business/src/Blockchain/Contracts/Native/DexContract.cs b/Phantasma.Business/src/Blockchain/Contracts/Native/DexContract.cs index 96d6f532..f9b4a264 100644 --- a/Phantasma.Business/src/Blockchain/Contracts/Native/DexContract.cs +++ b/Phantasma.Business/src/Blockchain/Contracts/Native/DexContract.cs @@ -76,6 +76,10 @@ public bool IsSupportedToken(string symbol) /// public void DepositTokens(Address from, string symbol, BigInteger amount) { + if (Runtime.ProtocolVersion >= 16) + { + Runtime.Expect(false, "This method is not available in this version of the DEX"); + } Runtime.Expect(Runtime.IsWitness(from), "invalid witness"); Runtime.Expect(from.IsUser, "address must be user address"); @@ -97,6 +101,10 @@ public void DepositTokens(Address from, string symbol, BigInteger amount) /// public void SwapTokens(Address from, string fromSymbol, string toSymbol, BigInteger amount) { + if (Runtime.ProtocolVersion >= 16) + { + Runtime.Expect(false, "This method is not available in this version of the DEX"); + } Runtime.Expect(_DEXversion >= 1, "call migrateV3 first"); Runtime.Expect(Runtime.IsWitness(from), "invalid witness"); Runtime.Expect(amount > 0, $"invalid amount, need to be higher than 0 | {amount}"); @@ -410,6 +418,11 @@ public void Migrate() /// public void MigrateToV3() { + if (Runtime.ProtocolVersion >= 16) + { + Runtime.Expect(false, "This method is not available in this version of the DEX"); + } + Runtime.Expect(_DEXversion == 0, "Migration failed, wrong version"); var existsLP = Runtime.TokenExists(DomainSettings.LiquidityTokenSymbol); @@ -1312,6 +1325,11 @@ private bool PoolExists(string symbol0, string symbol1) /// Amount for Symbol1 public void CreatePool(Address from, string symbol0, BigInteger amount0, string symbol1, BigInteger amount1) { + if (Runtime.ProtocolVersion >= 16) + { + Runtime.Expect(false, "This method is not available in this version of the DEX"); + } + ValidatePoolCreation(from, symbol0, amount0, symbol1, amount1); var token0Info = Runtime.GetToken(symbol0); @@ -1451,6 +1469,11 @@ private void MintLPTokensAndTransferToPool(Address from, string symbol0, BigInte /// Amount for Symbol1 public void AddLiquidity(Address from, string symbol0, BigInteger amount0, string symbol1, BigInteger amount1) { + if (Runtime.ProtocolVersion >= 16) + { + Runtime.Expect(false, "This method is not available in this version of the DEX"); + } + ValidateInputs(from, symbol0, amount0, symbol1, amount1); var token0Info = Runtime.GetToken(symbol0); @@ -1638,6 +1661,11 @@ private void UpdateLiquidity(Address from, string symbol0, string symbol1, BigIn /// Amount for Symbol1 public void AddLiquidityV1(Address from, string symbol0, BigInteger amount0, string symbol1, BigInteger amount1) { + if (Runtime.ProtocolVersion >= 16) + { + Runtime.Expect(false, "This method is not available in this version of the DEX"); + } + // Check input Runtime.Expect(Runtime.IsWitness(from), "invalid witness"); Runtime.Expect(amount0 >= 0, "invalid amount 0"); @@ -1787,6 +1815,11 @@ public void AddLiquidityV1(Address from, string symbol0, BigInteger amount0, str /// Amount for Symbol1 public void RemoveLiquidity(Address from, string symbol0, BigInteger amount0, string symbol1, BigInteger amount1) { + if (Runtime.ProtocolVersion >= 16) + { + Runtime.Expect(false, "This method is not available in this version of the DEX"); + } + ValidateInputs(from, symbol0, amount0, symbol1, amount1); // Check if user has LP Token @@ -2208,6 +2241,11 @@ private void DistributeFee(BigInteger totalFeeAmount, Pool pool, string symbolDi /// public void ClaimFees(Address from, string symbol0, string symbol1) { + if (Runtime.ProtocolVersion >= 16) + { + Runtime.Expect(false, "This method is not available in this version of the DEX"); + } + if ( Runtime.ProtocolVersion >= 14) Runtime.Expect(_DEXversion >= 1, " This method is not available in this version of the DEX"); Runtime.Expect(Runtime.IsWitness(from), "invalid witness"); @@ -2429,6 +2467,11 @@ private void DeleteNFT(Address from, string symbol0, BigInteger amount0, string public void BurnNFT(Address from, BigInteger nftID) { + if (Runtime.ProtocolVersion >= 16) + { + Runtime.Expect(false, "This method is not available in this version of the DEX"); + } + if ( Runtime.ProtocolVersion >= 14) Runtime.Expect(_DEXversion >= 1, " This method is not available in this version of the DEX"); if (!Runtime.NFTExists(DomainSettings.LiquidityTokenSymbol, nftID)) diff --git a/Phantasma.Business/src/Blockchain/Contracts/Native/ExchangeContract.cs b/Phantasma.Business/src/Blockchain/Contracts/Native/ExchangeContract.cs index 8aaa2529..58605cc3 100644 --- a/Phantasma.Business/src/Blockchain/Contracts/Native/ExchangeContract.cs +++ b/Phantasma.Business/src/Blockchain/Contracts/Native/ExchangeContract.cs @@ -117,9 +117,9 @@ private void ValidateExchangeParameters(string id, string name, BigInteger total public void CreateExchange(Address from, string id, string name, BigInteger totalFee, BigInteger feePercentForExchange, BigInteger feePercentForPool) { - if (Runtime.ProtocolVersion >= 15) + if (Runtime.ProtocolVersion >= 16) { - Runtime.Expect(false, "exchange not supported on this protocol version"); + Runtime.Expect(false, "This method is not available in this version of the DEX"); return; } @@ -152,9 +152,9 @@ public void CreateExchange(Address from, string id, string name, BigInteger tota public void EditExchange(Address from, string id, string name, BigInteger totalFee, BigInteger feePercentForExchange, BigInteger feePercentForPool) { - if (Runtime.ProtocolVersion >= 15) + if (Runtime.ProtocolVersion >= 16) { - Runtime.Expect(false, "exchange not supported on this protocol version"); + Runtime.Expect(false, "This method is not available in this version of the DEX"); return; } diff --git a/Phantasma.Business/src/Blockchain/Contracts/Native/StakeContract.cs b/Phantasma.Business/src/Blockchain/Contracts/Native/StakeContract.cs index 639d4d6b..b5e899a1 100644 --- a/Phantasma.Business/src/Blockchain/Contracts/Native/StakeContract.cs +++ b/Phantasma.Business/src/Blockchain/Contracts/Native/StakeContract.cs @@ -76,7 +76,8 @@ public void Initialize(Address from) } Runtime.Expect(Runtime.IsWitness(from), "invalid witness"); - Runtime.Expect(Runtime.IsKnownValidator(from), "invalid validator"); + if ( Runtime.HasGenesis ) + Runtime.Expect(Runtime.IsKnownValidator(from), "invalid validator"); _currentEnergyRatioDivisor = DefaultEnergyRatioDivisor; // used as 1/500, will initially generate 0.002 per staked token } diff --git a/Phantasma.Business/src/Blockchain/Nexus/Nexus.cs b/Phantasma.Business/src/Blockchain/Nexus/Nexus.cs index 650144f4..272428ff 100644 --- a/Phantasma.Business/src/Blockchain/Nexus/Nexus.cs +++ b/Phantasma.Business/src/Blockchain/Nexus/Nexus.cs @@ -367,7 +367,8 @@ private Transaction NexusCreateTx(PhantasmaKeys owner, Timestamp genesisTime, in // Generate extra KCAL in simnet only if (Name == DomainSettings.NexusSimnet) { - sb.MintTokens(DomainSettings.FuelTokenSymbol, owner.Address, owner.Address, UnitConversion.ToBigInteger(1000000, DomainSettings.FuelTokenDecimals)); + sb.MintTokens(DomainSettings.StakingTokenSymbol, owner.Address, owner.Address, UnitConversion.ToBigInteger(10000000, DomainSettings.StakingTokenDecimals)); + sb.MintTokens(DomainSettings.FuelTokenSymbol, owner.Address, owner.Address, UnitConversion.ToBigInteger(10000000, DomainSettings.FuelTokenDecimals)); } sb.CallContract(NativeContractKind.Validator, nameof(ValidatorContract.SetValidator), owner.Address, new BigInteger(0), ValidatorType.Primary); @@ -415,7 +416,7 @@ public void BeginInitialize(IRuntime vm, Address owner) CreateToken(storage, DomainSettings.FuelTokenSymbol, DomainSettings.FuelTokenName, owner, 0, DomainSettings.FuelTokenDecimals, TokenFlags.Fungible | TokenFlags.Transferable | TokenFlags.Divisible | TokenFlags.Burnable | TokenFlags.Fuel, tokenScript, abi); CreateToken(storage, DomainSettings.RewardTokenSymbol, DomainSettings.RewardTokenName, owner, 0, 0, TokenFlags.Transferable | TokenFlags.Burnable, tokenScript, abi); CreateToken(storage, DomainSettings.FiatTokenSymbol, DomainSettings.FiatTokenName, owner, 0, DomainSettings.FiatTokenDecimals, TokenFlags.Fungible | TokenFlags.Transferable | TokenFlags.Divisible | TokenFlags.Fiat, tokenScript, abi); - var lpABI = ContractInterface.FromBytes(Base16.Decode(NEW_LP_CONTRACT_ABI)); + //var lpABI = ContractInterface.FromBytes(Base16.Decode(NEW_LP_CONTRACT_ABI)); //CreateToken(storage, "LP", "Phantasma Liquidity Provider", owner, 0, 0, TokenFlags.Transferable | TokenFlags.Mintable | TokenFlags.Swappable | TokenFlags.Burnable, Base16.Decode(NEW_LP_CONTRACT_PVM), lpABI ); CreateToken(storage, "NEO", "NEO", owner, UnitConversion.ToBigInteger(100000000, 0), 0, TokenFlags.Fungible | TokenFlags.Transferable | TokenFlags.Finite, tokenScript, abi); diff --git a/Phantasma.Business/src/Blockchain/Nexus/NexusValidators.cs b/Phantasma.Business/src/Blockchain/Nexus/NexusValidators.cs index 099fa663..5113a9d6 100644 --- a/Phantasma.Business/src/Blockchain/Nexus/NexusValidators.cs +++ b/Phantasma.Business/src/Blockchain/Nexus/NexusValidators.cs @@ -8,8 +8,10 @@ using Phantasma.Core.Domain.Contract.Enums; using Phantasma.Core.Domain.Contract.Validator.Enums; using Phantasma.Core.Domain.Contract.Validator.Structs; +using Phantasma.Core.Domain.Interfaces; using Phantasma.Core.Domain.Validation; using Phantasma.Core.Storage.Context; +using Phantasma.Core.Storage.Context.Structs; using Phantasma.Core.Types.Structs; namespace Phantasma.Business.Blockchain; @@ -84,6 +86,7 @@ public bool IsSecondaryValidator(Address address, Timestamp timestamp) // this returns true for both active and waiting public bool IsKnownValidator(Address address, Timestamp timestamp) { + if (!HasGenesis()) return true; var result = GetValidatorType(address, timestamp); return result != ValidatorType.Invalid && result != ValidatorType.Proposed; } @@ -165,15 +168,15 @@ public ValidatorEntry GetValidator(StorageContext storage, string tAddress) var lastBlockHash = this.RootChain.GetLastBlockHash(); var lastBlock = this.RootChain.GetBlockByHash(lastBlockHash); // TODO use builtin methods instead of doing this directly - var validatorEntryVmObject = RootChain.InvokeContractAtTimestamp(storage, lastBlock.Timestamp, + /*var validatorEntryVmObject = RootChain.InvokeContractAtTimestamp(storage, lastBlock.Timestamp, NativeContractKind.Validator, nameof(ValidatorContract.GetCurrentValidator), tAddress); - return validatorEntryVmObject.AsStruct(); - /* - var valueMapKey = Encoding.UTF8.GetBytes($".{validatorContractName}._validators"); - var validators = new StorageMap(valueMapKey, storage); + return validatorEntryVmObject.AsStruct();*/ + + var valueMapKey = NativeContract.GetKeyForField(NativeContractKind.Validator, "_validators", true); + var validators = new StorageList(valueMapKey, storage); - foreach (var validator in validators.AllValues()) + foreach (var validator in validators.All()) { if (validator.address.TendermintAddress == tAddress) { @@ -186,7 +189,7 @@ public ValidatorEntry GetValidator(StorageContext storage, string tAddress) address = Address.Null, type = ValidatorType.Invalid, election = new Timestamp(0) - };*/ + }; } #endregion diff --git a/Phantasma.Business/src/Blockchain/Oracle.cs b/Phantasma.Business/src/Blockchain/Oracle.cs index 9f164b7a..8e6a088a 100644 --- a/Phantasma.Business/src/Blockchain/Oracle.cs +++ b/Phantasma.Business/src/Blockchain/Oracle.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Numerics; +using Phantasma.Business.Blockchain.Contracts; using Phantasma.Business.Blockchain.Contracts.Native; using Phantasma.Core; using Phantasma.Core.Cryptography; @@ -21,6 +22,8 @@ using Phantasma.Core.Domain.Serializer; using Phantasma.Core.Domain.Structs; using Phantasma.Core.Numerics; +using Phantasma.Core.Storage.Context; +using Phantasma.Core.Storage.Context.Structs; using Phantasma.Core.Types; using Phantasma.Core.Types.Structs; using Serilog; @@ -142,7 +145,10 @@ public virtual T Read(Timestamp time, string url) where T : class BigInteger exchangeVersion = 0; try { - exchangeVersion = Nexus.RootChain.InvokeContractAtTimestamp(Nexus.RootStorage, time, NativeContractKind.Exchange, nameof(ExchangeContract.GetDexVersion)).AsNumber(); + var keyForField = NativeContract.GetKeyForField(NativeContractKind.Exchange, "_DEXversion", true); + var storageValue = new StorageValue(keyForField, Nexus.RootStorage); + exchangeVersion = storageValue.Get(); + //exchangeVersion = Nexus.RootChain.InvokeContractAtTimestamp(Nexus.RootStorage, time, NativeContractKind.Exchange, nameof(ExchangeContract.GetDexVersion)).AsNumber(); } catch ( Exception e) { diff --git a/Phantasma.Business/tests/Blockchain/Contracts/ConcensusContractTests.cs b/Phantasma.Business/tests/Blockchain/Contracts/ConcensusContractTests.cs index 0e5e7632..1afa0f11 100644 --- a/Phantasma.Business/tests/Blockchain/Contracts/ConcensusContractTests.cs +++ b/Phantasma.Business/tests/Blockchain/Contracts/ConcensusContractTests.cs @@ -89,12 +89,13 @@ protected void SetInitialBalance(Address address) simulator.GenerateTransfer(owner, address, nexus.RootChain, DomainSettings.FuelTokenSymbol, initialFuel); simulator.GenerateTransfer(owner, address, nexus.RootChain, DomainSettings.StakingTokenSymbol, initialAmount); simulator.EndBlock(); + Assert.True(simulator.LastBlockWasSuccessful(), simulator.FailedTxReason); simulator.BeginBlock(); simulator.GenerateTransfer(owner, address, nexus.RootChain, DomainSettings.FuelTokenSymbol, initialFuel); simulator.GenerateTransfer(owner, address, nexus.RootChain, DomainSettings.StakingTokenSymbol, 100000000000); simulator.EndBlock(); - Assert.True(simulator.LastBlockWasSuccessful()); + Assert.True(simulator.LastBlockWasSuccessful(), simulator.FailedTxReason); } [Fact] diff --git a/Phantasma.Business/tests/Blockchain/Contracts/GasContractTests.cs b/Phantasma.Business/tests/Blockchain/Contracts/GasContractTests.cs index 8015f4f7..408e322b 100644 --- a/Phantasma.Business/tests/Blockchain/Contracts/GasContractTests.cs +++ b/Phantasma.Business/tests/Blockchain/Contracts/GasContractTests.cs @@ -148,7 +148,7 @@ public void TestInflation() phantomOrg.Address, simulator.CurrentTime); // Initial Supply - 171462300000000 var tokenSupplySOUL = simulator.Nexus.RootChain.GetTokenSupply(simulator.Nexus.RootStorage, "SOUL"); - Assert.Equal(171462300000000, tokenSupplySOUL); + Assert.Equal(1171462300000000, tokenSupplySOUL); var InflationPerYear = 133; var currentSupply = tokenSupplySOUL; diff --git a/Phantasma.Business/tests/Blockchain/ExtCallsTests.cs b/Phantasma.Business/tests/Blockchain/ExtCallsTests.cs index 1f346f13..47fb020c 100644 --- a/Phantasma.Business/tests/Blockchain/ExtCallsTests.cs +++ b/Phantasma.Business/tests/Blockchain/ExtCallsTests.cs @@ -84,7 +84,7 @@ public void TestDeployContractInsideContract() simulator.BeginBlock(); simulator.GenerateTransfer(owner, contract.Address, nexus.RootChain, DomainSettings.FuelTokenSymbol, initialFuel); simulator.EndBlock(); - + Assert.True(simulator.LastBlockWasSuccessful(), simulator.FailedTxReason); simulator.BeginBlock(); var tx = simulator.GenerateCustomTransaction(user, ProofOfWork.Minimal, @@ -114,7 +114,7 @@ public void TestDeployContractInsideContract() } - [Fact] + [Fact(Skip = "TODO")] public void TestDeployToken() { var contractName = "mintcontract"; @@ -125,6 +125,7 @@ public void TestDeployToken() // Send Tokens to Contract simulator.BeginBlock(); simulator.GenerateTransfer(owner, contract.Address, nexus.RootChain, DomainSettings.FuelTokenSymbol, initialFuel); + simulator.GenerateTransfer(owner, contract.Address, nexus.RootChain, DomainSettings.StakingTokenSymbol, UnitConversion.ToBigInteger(20000, DomainSettings.StakingTokenDecimals)); simulator.EndBlock(); Assert.True(simulator.LastBlockWasSuccessful(), simulator.FailedTxReason); diff --git a/Phantasma.Business/tests/Blockchain/FilterTests.cs b/Phantasma.Business/tests/Blockchain/FilterTests.cs index 7274bfa4..7a4b4fcc 100644 --- a/Phantasma.Business/tests/Blockchain/FilterTests.cs +++ b/Phantasma.Business/tests/Blockchain/FilterTests.cs @@ -27,8 +27,7 @@ public class FilterTests public void SimpleFilter() { var owner = PhantasmaKeys.Generate(); - - var simulator = new NexusSimulator(owner); + var simulator = new NexusSimulator(new [] {owner}, 9); var nexus = simulator.Nexus; var testUser = PhantasmaKeys.Generate(); @@ -57,7 +56,7 @@ public void SimpleFilter() simulator.GenerateTransfer(owner, testUser.Address, nexus.RootChain, DomainSettings.StakingTokenSymbol, transferAmount); simulator.EndBlock(); - Assert.False(simulator.LastBlockWasSuccessful()); + Assert.False(simulator.LastBlockWasSuccessful(), simulator.FailedTxReason); var hashes = simulator.Nexus.RootChain.GetTransactionHashesForAddress(testUser.Address); Assert.True(hashes.Length == 1); @@ -80,7 +79,7 @@ public void TestRemoveFilter() { var owner = PhantasmaKeys.Generate(); - var simulator = new NexusSimulator(owner); + var simulator = new NexusSimulator(new [] {owner}, 9); var nexus = simulator.Nexus; var testUser = PhantasmaKeys.Generate(); @@ -113,7 +112,7 @@ public void TestRemoveFilter() simulator.GenerateTransfer(sender, testUser.Address, nexus.RootChain, DomainSettings.StakingTokenSymbol, transferAmount); simulator.EndBlock(); - Assert.False(simulator.LastBlockWasSuccessful()); + Assert.False(simulator.LastBlockWasSuccessful(), simulator.FailedTxReason); var hashes = simulator.Nexus.RootChain.GetTransactionHashesForAddress(testUser.Address); Assert.True(hashes.Length == 1); @@ -136,7 +135,7 @@ public void TestRemoveFilter() simulator.GenerateTransfer(sender, testUser.Address, nexus.RootChain, DomainSettings.StakingTokenSymbol, smallAmount); simulator.EndBlock(); - Assert.True(simulator.LastBlockWasSuccessful()); + Assert.True(simulator.LastBlockWasSuccessful(), simulator.FailedTxReason); finalBalance = simulator.Nexus.RootChain.GetTokenBalance(simulator.Nexus.RootStorage, stakeToken, owner.Address); @@ -149,7 +148,7 @@ public void TestAddRedFilteGreenFilter() { var owner = PhantasmaKeys.Generate(); - var simulator = new NexusSimulator(owner); + var simulator = new NexusSimulator(new [] {owner}, 9); var nexus = simulator.Nexus; var testUser = PhantasmaKeys.Generate(); @@ -184,7 +183,7 @@ public void TestAddRedFilteGreenFilter() simulator.GenerateTransfer(sender, testUser.Address, nexus.RootChain, DomainSettings.StakingTokenSymbol, transferAmount); simulator.EndBlock(); - Assert.False(simulator.LastBlockWasSuccessful()); + Assert.False(simulator.LastBlockWasSuccessful(), simulator.FailedTxReason); var hashes = simulator.Nexus.RootChain.GetTransactionHashesForAddress(testUser.Address); Assert.True(hashes.Length == 1); @@ -225,7 +224,7 @@ public void FilterQuotaReached() { var owner = PhantasmaKeys.Generate(); - var simulator = new NexusSimulator(owner); + var simulator = new NexusSimulator(new [] {owner}, 9); var nexus = simulator.Nexus; var testUser = PhantasmaKeys.Generate(); @@ -265,22 +264,22 @@ public void FilterQuotaReached() Assert.True(transferAmount > 0); simulator.BeginBlock(); - simulator.GenerateTransfer(owner, testUser.Address, nexus.RootChain, DomainSettings.StakingTokenSymbol, + simulator.GenerateTransfer(sender, testUser.Address, nexus.RootChain, DomainSettings.StakingTokenSymbol, transferAmount); simulator.EndBlock(); if (i == totalSplits - 1) // only last is expected to fail { - Assert.False(simulator.LastBlockWasSuccessful()); + Assert.False(simulator.LastBlockWasSuccessful(), simulator.FailedTxReason); } else { - Assert.True(simulator.LastBlockWasSuccessful()); + Assert.True(simulator.LastBlockWasSuccessful(), simulator.FailedTxReason); } } var hashes = simulator.Nexus.RootChain.GetTransactionHashesForAddress(testUser.Address); - Assert.True(hashes.Length == totalSplits); + Assert.Equal(hashes.Length, totalSplits ); BigInteger expectedBalance = split * (totalSplits - 1); // last one is supposed to fail expectedBalance *= UnitConversion.GetUnitValue(DomainSettings.StakingTokenDecimals); @@ -289,7 +288,7 @@ public void FilterQuotaReached() simulator.Nexus.GetTokenInfo(simulator.Nexus.RootStorage, DomainSettings.StakingTokenSymbol); var finalBalance = simulator.Nexus.RootChain.GetTokenBalance(simulator.Nexus.RootStorage, stakeToken, testUser.Address); - Assert.True(finalBalance == expectedBalance); + Assert.Equal(finalBalance, expectedBalance); if (nexus.GetProtocolVersion(nexus.RootStorage) <= 9) { diff --git a/Phantasma.Business/tests/Blockchain/RuntimeTestsSimulator.cs b/Phantasma.Business/tests/Blockchain/RuntimeTestsSimulator.cs index 3376b1d9..eb458a9f 100644 --- a/Phantasma.Business/tests/Blockchain/RuntimeTestsSimulator.cs +++ b/Phantasma.Business/tests/Blockchain/RuntimeTestsSimulator.cs @@ -72,7 +72,7 @@ protected void SetInitialBalance(Address address) simulator.GenerateTransfer(owner, address, nexus.RootChain, DomainSettings.FuelTokenSymbol, initialFuel); simulator.GenerateTransfer(owner, address, nexus.RootChain, DomainSettings.StakingTokenSymbol, initialAmount); simulator.EndBlock(); - Assert.True(simulator.LastBlockWasSuccessful()); + Assert.True(simulator.LastBlockWasSuccessful(), simulator.FailedTxReason); } [Fact] diff --git a/Phantasma.Core/tests/Utils/RequestTests.cs b/Phantasma.Core/tests/Utils/RequestTests.cs index 64ac242c..ec24b9a5 100644 --- a/Phantasma.Core/tests/Utils/RequestTests.cs +++ b/Phantasma.Core/tests/Utils/RequestTests.cs @@ -73,7 +73,7 @@ public void TestRequestBlockHeight() public void TestRequestGetBlockByHeight() { var postParms = ""; - var urlRequest = "http://testnet.phantasma.io:5101/api/v1/GetBlockByHeight?chainInput=main&height=1"; + var urlRequest = "https://testnet.phantasma.io/api/v1/GetBlockByHeight?chainInput=main&height=1"; var request = RequestUtils.Request(RequestType.GET, urlRequest, out string myResponse); var block = new BlockResult(); @@ -89,7 +89,7 @@ public void TestRequestGetBlockByHeight() public void TestRequestAsync() { var postParms = ""; - var urlRequest = "http://testnet.phantasma.io:5101/api/v1/GetBlockByHeight?chainInput=main&height=1"; + var urlRequest = "https://testnet.phantasma.io/api/v1/GetBlockByHeight?chainInput=main&height=1"; var request = RequestUtils.RequestAsync(RequestType.GET, urlRequest); var block = new BlockResult(); diff --git a/Phantasma.Node/src/ABCIConnector.cs b/Phantasma.Node/src/ABCIConnector.cs index edcc91ca..c3784b3b 100644 --- a/Phantasma.Node/src/ABCIConnector.cs +++ b/Phantasma.Node/src/ABCIConnector.cs @@ -293,8 +293,11 @@ public override Task Commit(RequestCommit request, ServerCallCon Log.Information($"ABCI Connector - Commit"); var chain = _nexus.RootChain as Chain; + // Is signed by me and I am the proposer - Log.Information("Block {Height} is signed by {Address}", chain.Height, chain.CurrentBlock.Validator); + if ( chain.CurrentBlock != null) + Log.Information("Block {Height} is signed by {Address}", chain.Height, chain.CurrentBlock.Validator); + if (chain.CurrentBlock.Validator == chain.ValidatorAddress) { Log.Information("Block {Height} Is Being Validated by me."); diff --git a/README.md b/README.md index 23d11790..6f4c5a8f 100644 --- a/README.md +++ b/README.md @@ -100,6 +100,36 @@ If you need to develop on Linux or macOS, just install the [.NET Core SDK](https For more information about how to build dApps for Phantasma, please read the [documentation](http://phantasma.io/development). +## Debuging + +To effectively debug `Phantasma.Node`, follow the steps outlined below: + +1. **Tendermint Executable**: + - To debug `Phantasma.Node`, it's essential to have the `tendermint` executable. + - Download it from this URL: [Tendermint v0.34.21 Release](https://github.com/tendermint/tendermint/releases/tag/v0.34.21). + - Place the downloaded executable inside the path: `/path/to/phantasma-ng/Phantasma.Node/src/bin/Debug/net6.0/tendermintFile`. + +2. **Configuration Settings**: + - In the `config.json` file, ensure that you specify the path to the folder mentioned above and the `tendermint` executable. + - You can find an example configuration in the `Phantasma.Node/src` directory. + +3. **Reset the Blockchain**: + - Delete the `Storage` folder. + - Remove the `Storage` folder located at `/path/to/phantasma-ng/Phantasma.Node/src/bin/Debug/net6.0/`. + - Remove the `data` folder found inside `/path/to/phantasma-ng/Phantasma.Node/src/bin/Debug/net6.0/tendermintFile`. + - Navigate to the `DOCKER` folder using a terminal and execute the script: `./fix-storage.sh`. This will reset the blockchain. + - An easy way to do the deployment and reset in on step is to run this command: `cd DOCKER && ./fix-storage.sh || cd .. && ./testnet-startup.sh`. +4. **Edit Necessary Files for Protocol Version**: + - In `Phantasma.Business/src/Blockchain/Nexus/Nexus.cs`: + - Update the value of `DomainSettings.Phantasma30Protocol` to `DomainSettings.LatestKnownProtocol` at lines 937, 961, and 978. + - In `Phantasma.Node/src/ABCIConnector.cs`: + - Update the value on line 420 from `uint version = DomainSettings.Phantasma30Protocol;` to `uint version = DomainSettings.LatestKnownProtocol;`. + +5. **Run Node in Editor**: + - If you intend to run the node in an editor like Rider or Visual Studio for debugging purposes: + - Edit the `DOCKER/wrapper-testnet.sh` file. + - Comment out line 28. + ## Contributing You can contribute to Phantasma with [issues](https://github.com/Phantasma-io/PhantasmaChain/issues) and [PRs](https://github.com/Phantasma-io/PhantasmaChain/pulls). Simply filing issues for problems you encounter is a great way to contribute. Contributing implementations is greatly appreciated. diff --git a/build-docker-testnet-arm64.sh b/build-docker-testnet-arm64.sh index 68a3d730..302a81f1 100755 --- a/build-docker-testnet-arm64.sh +++ b/build-docker-testnet-arm64.sh @@ -6,7 +6,7 @@ TESTNET_ROOT='./DOCKER/testnet' PUBLISH_ROOT='./Phantasma.Node/src/bin/Debug/net6.0/linux-arm64/publish/' NODE_PROJ='Phantasma.Node/src/Phantasma.Node.csproj' LAST_COMMIT=`git rev-parse --short HEAD` - +#https://github.com/tendermint/tendermint/releases/download/v0.34.21/tendermint_0.34.21_macos_arm64.tar.gz wget --no-check-certificate --content-disposition https://github.com/tendermint/tendermint/releases/download/v"$VERSION"/tendermint_"$VERSION"_linux_arm64.tar.gz mkdir -p DOCKER/bin diff --git a/build-docker-testnet-debug-arm64.sh b/build-docker-testnet-debug-arm64.sh new file mode 100644 index 00000000..a8626ae1 --- /dev/null +++ b/build-docker-testnet-debug-arm64.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +#VERSION=0.35.6 +VERSION=0.34.21 +TESTNET_ROOT='./DOCKER/testnet' +PUBLISH_ROOT='./Phantasma.Node/src/bin/Debug/net6.0/linux-arm64/publish/' +NODE_PROJ='Phantasma.Node/src/Phantasma.Node.csproj' +LAST_COMMIT=`git rev-parse --short HEAD` +#https://github.com/tendermint/tendermint/releases/download/v0.34.21/tendermint_0.34.21_macos_arm64.tar.gz +wget --no-check-certificate --content-disposition https://github.com/tendermint/tendermint/releases/download/v"$VERSION"/tendermint_"$VERSION"_linux_arm64.tar.gz + +mkdir -p DOCKER/bin + +tar -xzf tendermint_"$VERSION"_linux_arm64.tar.gz -C DOCKER/bin/ + +rm tendermint_"$VERSION"_linux_arm64.tar.gz + +dotnet publish "$NODE_PROJ" --sc -r linux-arm64 + +mkdir -p "$TESTNET_ROOT"/node0/publish/ +mkdir -p "$TESTNET_ROOT"/node1/publish/ +mkdir -p "$TESTNET_ROOT"/node2/publish/ +mkdir -p "$TESTNET_ROOT"/node3/publish/ + +cp -R "$PUBLISH_ROOT"* "$TESTNET_ROOT"/node0/publish +cp -R "$PUBLISH_ROOT"* "$TESTNET_ROOT"/node1/publish +cp -R "$PUBLISH_ROOT"* "$TESTNET_ROOT"/node2/publish +cp -R "$PUBLISH_ROOT"* "$TESTNET_ROOT"/node3/publish + +cp -R "$TESTNET_ROOT"/node0/config_node0.json "$TESTNET_ROOT"/node0/publish/config.json +cp -R "$TESTNET_ROOT"/node1/config_node1.json "$TESTNET_ROOT"/node1/publish/config.json +cp -R "$TESTNET_ROOT"/node2/config_node2.json "$TESTNET_ROOT"/node2/publish/config.json +cp -R "$TESTNET_ROOT"/node3/config_node3.json "$TESTNET_ROOT"/node3/publish/config.json + +docker build --platform=linux/arm64 -t phantasma-devnet -f DOCKER/DockerfileTestnetDebug . + +docker tag phantasma-devnet:latest phantasmachain/phantasma-devnet:$LAST_COMMIT \ No newline at end of file diff --git a/build-docker-testnet-debug.sh b/build-docker-testnet-debug.sh new file mode 100644 index 00000000..e58c55be --- /dev/null +++ b/build-docker-testnet-debug.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +#VERSION=0.35.6 +VERSION=0.34.21 +TESTNET_ROOT='./DOCKER/testnet' +PUBLISH_ROOT='./Phantasma.Node/src/bin/Debug/net6.0/linux-x64/publish/' +NODE_PROJ='Phantasma.Node/src/Phantasma.Node.csproj' +LAST_COMMIT=`git rev-parse --short HEAD` + +wget --no-check-certificate --content-disposition https://github.com/tendermint/tendermint/releases/download/v"$VERSION"/tendermint_"$VERSION"_linux_amd64.tar.gz + +mkdir -p DOCKER/bin + +tar -xzf tendermint_"$VERSION"_linux_amd64.tar.gz -C DOCKER/bin/ + +rm tendermint_"$VERSION"_linux_amd64.tar.gz + +dotnet publish "$NODE_PROJ" --sc -r linux-x64 + +mkdir -p "$TESTNET_ROOT"/node0/publish/ +mkdir -p "$TESTNET_ROOT"/node1/publish/ +mkdir -p "$TESTNET_ROOT"/node2/publish/ +mkdir -p "$TESTNET_ROOT"/node3/publish/ + +cp -R "$PUBLISH_ROOT"* "$TESTNET_ROOT"/node0/publish +cp -R "$PUBLISH_ROOT"* "$TESTNET_ROOT"/node1/publish +cp -R "$PUBLISH_ROOT"* "$TESTNET_ROOT"/node2/publish +cp -R "$PUBLISH_ROOT"* "$TESTNET_ROOT"/node3/publish + +cp -R "$TESTNET_ROOT"/node0/config_node0.json "$TESTNET_ROOT"/node0/publish/config.json +cp -R "$TESTNET_ROOT"/node1/config_node1.json "$TESTNET_ROOT"/node1/publish/config.json +cp -R "$TESTNET_ROOT"/node2/config_node2.json "$TESTNET_ROOT"/node2/publish/config.json +cp -R "$TESTNET_ROOT"/node3/config_node3.json "$TESTNET_ROOT"/node3/publish/config.json + +docker build --platform=linux/x86_64 -t phantasma-devnet -f DOCKER/DockerfileTestnetDebug . + +docker tag phantasma-devnet:latest phantasmachain/phantasma-devnet:LAST_COMMIT \ No newline at end of file diff --git a/testnet-debug-arm64.sh b/testnet-debug-arm64.sh new file mode 100644 index 00000000..7de16261 --- /dev/null +++ b/testnet-debug-arm64.sh @@ -0,0 +1,16 @@ +#!/bin/bash +#if [[ $(id -u) -ne 0 ]] ; then echo "Please run as root" ; exit 1 ; fi + +# Stop old containers +docker container stop phantasma-devnet +docker container rm phantasma-devnet + +# Remove old images +echo y | docker image prune -a + +# Run the build script +chmod u+x ./build-docker-testnet-arm64-debug.sh +./build-docker-testnet-arm64-debug.sh + +# Run the testnet +docker run --name phantasma-devnet -v $(pwd)/DOCKER/testnet:/app/testnet -tid -p 7078:7078 -p 26156:26156 -p 26256:26256 -p 26356:26356 -p 26157:26157 -p 26257:26257 -p 26357:26357 phantasma-devnet diff --git a/testnet-debug.sh b/testnet-debug.sh new file mode 100644 index 00000000..991b952c --- /dev/null +++ b/testnet-debug.sh @@ -0,0 +1,16 @@ +#!/bin/bash +#if [[ $(id -u) -ne 0 ]] ; then echo "Please run as root" ; exit 1 ; fi + +# Stop old containers +docker container stop phantasma-devnet +docker container rm phantasma-devnet + +# Remove old images +echo y | docker image prune -a + +# Run the build script +chmod u+x ./build-docker-testnet-debug.sh +./build-docker-testnet-debug.sh + +# Run the testnet +docker run --name phantasma-devnet -v $(pwd)/DOCKER/testnet:/app/testnet -tid -p 7078:7078 -p 26156:26156 -p 26256:26256 -p 26356:26356 -p 26157:26157 -p 26257:26257 -p 26357:26357 phantasma-devnet diff --git a/testnet-startup-arm64.sh b/testnet-startup-arm64.sh index a4143768..d4f4e544 100755 --- a/testnet-startup-arm64.sh +++ b/testnet-startup-arm64.sh @@ -13,4 +13,4 @@ chmod u+x ./build-docker-testnet-arm64.sh ./build-docker-testnet-arm64.sh # Run the testnet -docker run --name phantasma-devnet -v $(pwd)/DOCKER/testnet:/app/testnet -tid -p 7078:7078 -p 7077:7077 -p 26056:26056 -p 26156:26156 -p 26256:26256 -p 26356:26356 -p 26057:26057 -p 26157:26157 -p 26257:26257 -p 26357:26357 phantasma-devnet \ No newline at end of file +docker run --name phantasma-devnet -v $(pwd)/DOCKER/testnet:/app/testnet -tid -p 7078:7078 -p 7077:7077 -p 26056:26056 -p 26156:26156 -p 26256:26256 -p 26356:26356 -p 26057:26057 -p 26157:26157 -p 26257:26257 -p 26357:26357 phantasma-devnet diff --git a/testnet-startup.sh b/testnet-startup.sh index c841e081..602d9a5d 100755 --- a/testnet-startup.sh +++ b/testnet-startup.sh @@ -13,4 +13,4 @@ chmod u+x ./build-docker-testnet.sh ./build-docker-testnet.sh # Run the testnet -docker run --name phantasma-devnet -v $(pwd)/DOCKER/testnet:/app/testnet -tid -p 5102:5102 -p 5101:5101 -p 26057:26057 phantasma-devnet \ No newline at end of file +docker run --name phantasma-devnet -v $(pwd)/DOCKER/testnet:/app/testnet -tid -p 7078:7078 -p 7077:7077 -p 26056:26056 -p 26156:26156 -p 26256:26256 -p 26356:26356 -p 26057:26057 -p 26157:26157 -p 26257:26257 -p 26357:26357 phantasma-devnet \ No newline at end of file