Commit 73573c27 authored by Sergei Zubov's avatar Sergei Zubov

Merge branch 'test' into 'release'

Add fee free transactions to own addresses

See merge request !1
parents 3dafe424 b077bb71
Pipeline #745 failed with stages
in 45 seconds
...@@ -10,11 +10,6 @@ stages: ...@@ -10,11 +10,6 @@ stages:
build_dev: build_dev:
stage: build_dev stage: build_dev
image: docker:stable image: docker:stable
services:
- docker:dind
variables:
DOCKER_HOST: tcp://docker:2375
DOCKER_DRIVER: overlay2
script: script:
- docker login -u "gitlab-ci-token" -p ${CI_JOB_TOKEN} ${CI_REGISTRY} - docker login -u "gitlab-ci-token" -p ${CI_JOB_TOKEN} ${CI_REGISTRY}
- docker build -t ${CI_REGISTRY_IMAGE}/dev:${CI_PIPELINE_ID} . - docker build -t ${CI_REGISTRY_IMAGE}/dev:${CI_PIPELINE_ID} .
...@@ -30,11 +25,6 @@ build_dev: ...@@ -30,11 +25,6 @@ build_dev:
build_test: build_test:
stage: build_test stage: build_test
image: docker:stable image: docker:stable
services:
- docker:dind
variables:
DOCKER_HOST: tcp://docker:2375
DOCKER_DRIVER: overlay2
script: script:
- docker login -u "gitlab-ci-token" -p ${CI_JOB_TOKEN} ${CI_REGISTRY} - docker login -u "gitlab-ci-token" -p ${CI_JOB_TOKEN} ${CI_REGISTRY}
- docker build -t ${CI_REGISTRY_IMAGE}/test:${CI_PIPELINE_ID} . - docker build -t ${CI_REGISTRY_IMAGE}/test:${CI_PIPELINE_ID} .
...@@ -70,11 +60,6 @@ build_prod: ...@@ -70,11 +60,6 @@ build_prod:
deploy_to_test: deploy_to_test:
stage: deploy_to_test stage: deploy_to_test
image: docker:stable image: docker:stable
services:
- docker:dind
variables:
DOCKER_HOST: tcp://docker:2375
DOCKER_DRIVER: overlay2
script: script:
- sed 's|_IMAGE_NAME_|'"${CI_REGISTRY_IMAGE}/test"'|g; s|_VERSION_|'"${CI_PIPELINE_ID}"'|g' app.tpl.yml > app.yml; cat app.yml - sed 's|_IMAGE_NAME_|'"${CI_REGISTRY_IMAGE}/test"'|g; s|_VERSION_|'"${CI_PIPELINE_ID}"'|g' app.tpl.yml > app.yml; cat app.yml
- wget https://storage.googleapis.com/kubernetes-release/release/v1.13.3/bin/linux/amd64/kubectl && chmod +x ./kubectl - wget https://storage.googleapis.com/kubernetes-release/release/v1.13.3/bin/linux/amd64/kubectl && chmod +x ./kubectl
...@@ -92,11 +77,6 @@ deploy_to_test: ...@@ -92,11 +77,6 @@ deploy_to_test:
run_test: run_test:
stage: run_tests stage: run_tests
image: docker:stable image: docker:stable
services:
- docker:dind
variables:
DOCKER_HOST: tcp://docker:2375
DOCKER_DRIVER: overlay2
script: script:
- docker build -f Dockerfile-tests . - docker build -f Dockerfile-tests .
allow_failure: true allow_failure: true
......
...@@ -34,8 +34,8 @@ namespace NBitcoin ...@@ -34,8 +34,8 @@ namespace NBitcoin
int changeIndex = ctx.Transaction.Outputs.FindIndex(p => int changeIndex = ctx.Transaction.Outputs.FindIndex(p =>
p.ScriptPubKey == group.ChangeScript[(int) ctx.ChangeType]); p.ScriptPubKey == group.ChangeScript[(int) ctx.ChangeType]);
if (changeIndex == -1) return result; if (changeIndex != -1)
{
var outPoint = new OutPoint var outPoint = new OutPoint
{ {
Hash = uint256.Zero, Hash = uint256.Zero,
...@@ -48,7 +48,31 @@ namespace NBitcoin ...@@ -48,7 +48,31 @@ namespace NBitcoin
}); });
group.Coins.Add(outPoint, new Coin(uint256.Zero, outPoint.N, group.Coins.Add(outPoint, new Coin(uint256.Zero, outPoint.N,
Money.Zero, @group.ChangeScript[(int) ctx.ChangeType])); Money.Zero, group.ChangeScript[(int) ctx.ChangeType]));
}
foreach (var ownAddress in group.ownAddresses)
{
var ownAddressOutputIndex = ctx.Transaction.Outputs.FindIndex(p =>
string.Equals(p.ScriptPubKey.GetDestinationAddress(this.Network).ToString(), ownAddress));
if(ownAddressOutputIndex == -1 || ownAddressOutputIndex == changeIndex)
continue;
var outPoint = new OutPoint
{
Hash = uint256.Zero,
N = (uint) ownAddressOutputIndex
};
ctx.Transaction.AddInput(new TxIn
{
PrevOut = outPoint
});
group.Coins.Add(outPoint, new Coin(uint256.Zero, outPoint.N,
Money.Zero, ctx.Transaction.Outputs[ownAddressOutputIndex].ScriptPubKey));
}
return result; return result;
} }
......
...@@ -495,6 +495,7 @@ namespace NBitcoin ...@@ -495,6 +495,7 @@ namespace NBitcoin
internal List<Builder> IssuanceBuilders = new List<Builder>(); internal List<Builder> IssuanceBuilders = new List<Builder>();
internal Dictionary<AssetId, List<Builder>> BuildersByAsset = new Dictionary<AssetId, List<Builder>>(); internal Dictionary<AssetId, List<Builder>> BuildersByAsset = new Dictionary<AssetId, List<Builder>>();
internal Script[] ChangeScript = new Script[3]; internal Script[] ChangeScript = new Script[3];
internal IEnumerable<string> ownAddresses { get; set; }
internal void Shuffle() internal void Shuffle()
{ {
Shuffle(this.Builders); Shuffle(this.Builders);
...@@ -1074,6 +1075,12 @@ namespace NBitcoin ...@@ -1074,6 +1075,12 @@ namespace NBitcoin
return this; return this;
} }
public TransactionBuilder SetOwnAddresses(IEnumerable<string> ownAddresses)
{
this.CurrentGroup.ownAddresses = ownAddresses;
return this;
}
public TransactionBuilder SetCoinSelector(ICoinSelector selector) public TransactionBuilder SetCoinSelector(ICoinSelector selector)
{ {
if(selector == null) if(selector == null)
......
...@@ -47,7 +47,7 @@ namespace Stratis.Bitcoin.Features.Miner ...@@ -47,7 +47,7 @@ namespace Stratis.Bitcoin.Features.Miner
private readonly IDateTimeProvider dateTimeProvider; private readonly IDateTimeProvider dateTimeProvider;
/// <summary>Default for "-blockmintxfee", which sets the minimum feerate for a transaction in blocks created by mining code.</summary> /// <summary>Default for "-blockmintxfee", which sets the minimum feerate for a transaction in blocks created by mining code.</summary>
public const int DefaultBlockMinTxFee = 1000; public const int DefaultBlockMinTxFee = 0;
private uint256 hashPrevBlock; private uint256 hashPrevBlock;
......
...@@ -110,5 +110,14 @@ namespace Stratis.Bitcoin.Features.Wallet ...@@ -110,5 +110,14 @@ namespace Stratis.Bitcoin.Features.Wallet
return newAddress; return newAddress;
} }
public IEnumerable<string> GetOwnAddresses(WalletAccountReference accountReference)
{
return GetAccounts(accountReference.WalletName)
.Single(q => q.Name == accountReference.AccountName).ExternalAddresses
.Select(q => q.Address).Concat(GetAccounts(accountReference.WalletName)
.Single(q => q.Name == accountReference.AccountName).InternalAddresses
.Select(q => q.Address));
}
} }
} }
\ No newline at end of file
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security; using System.Security;
...@@ -30,10 +30,25 @@ namespace Stratis.Bitcoin.Features.Wallet ...@@ -30,10 +30,25 @@ namespace Stratis.Bitcoin.Features.Wallet
} }
} }
protected override void InitializeTransactionBuilder(TransactionBuildContext context)
{
base.InitializeTransactionBuilder(context);
this.AddOwnAddresses(context);
}
private void AddOwnAddresses(TransactionBuildContext context)
{
context.TransactionBuilder.SetOwnAddresses(
(this.walletManager as IDeStreamWalletManager).GetOwnAddresses(context.AccountReference));
}
/// <inheritdoc /> /// <inheritdoc />
protected override void AddFee(TransactionBuildContext context) protected override void AddFee(TransactionBuildContext context)
{ {
long fee = Convert.ToInt64(context.Recipients.Sum(p => p.Amount) * this.DeStreamNetwork.FeeRate); var fundTransfers = context.Recipients.Where(p => !(this.walletManager as IDeStreamWalletManager).GetOwnAddresses(context.AccountReference)
.Contains(p.ScriptPubKey.GetDestinationAddress(this.network).ToString()));
long fee = Convert.ToInt64(fundTransfers.Sum(p => p.Amount) * this.DeStreamNetwork.FeeRate);
context.TransactionFee = fee; context.TransactionFee = fee;
context.TransactionBuilder.SendFees(fee); context.TransactionBuilder.SendFees(fee);
} }
...@@ -137,6 +152,29 @@ namespace Stratis.Bitcoin.Features.Wallet ...@@ -137,6 +152,29 @@ namespace Stratis.Bitcoin.Features.Wallet
seedExtKey.Derive(new KeyPath(context.ChangeAddress.HdPath)).GetWif(wallet.Network); seedExtKey.Derive(new KeyPath(context.ChangeAddress.HdPath)).GetWif(wallet.Network);
signingKeys.Add(changeAddressPrivateKey); signingKeys.Add(changeAddressPrivateKey);
var transfersToSelf = context.Recipients.Where(p =>
(this.walletManager as IDeStreamWalletManager).GetOwnAddresses(context.AccountReference)
.Contains(p.ScriptPubKey.GetDestinationAddress(this.network).ToString()) && context.UnspentOutputs.All(q => p.ScriptPubKey != q.Address.ScriptPubKey));
foreach (var ownAddress in transfersToSelf)
{
var ownHdAddress = this.walletManager.GetAccounts(context.AccountReference.WalletName)
.Single(q => q.Name == context.AccountReference.AccountName).GetCombinedAddresses()
.Single(p => string.Equals(ownAddress.ScriptPubKey.GetDestinationAddress(this.network).ToString(), p.Address));
var ownAddressPrivateKey = seedExtKey.Derive(new KeyPath(ownHdAddress.HdPath)).GetWif(wallet.Network);
signingKeys.Add(ownAddressPrivateKey);
}
// signingKeys.UnionWith(context.Recipients.Where(p =>
// (this.walletManager as IDeStreamWalletManager).GetOwnAddresses(context.AccountReference)
// .Contains(p.ScriptPubKey.GetDestinationAddress(this.network).ToString()) &&
// context.UnspentOutputs.All(q => p.ScriptPubKey != q.Address.ScriptPubKey)).Select(r =>
// seedExtKey.Derive(new KeyPath(this.walletManager.GetAccounts(context.AccountReference.WalletName)
// .Single(q => q.Name == context.AccountReference.AccountName).GetCombinedAddresses()
// .Single(p =>
// string.Equals(r.ScriptPubKey.GetDestinationAddress(this.network).ToString(), p.Address))
// .HdPath)).GetWif(wallet.Network)));
context.TransactionBuilder.AddKeys(signingKeys.ToArray()); context.TransactionBuilder.AddKeys(signingKeys.ToArray());
} }
......
namespace Stratis.Bitcoin.Features.Wallet.Interfaces using System.Collections.Generic;
namespace Stratis.Bitcoin.Features.Wallet.Interfaces
{ {
public interface IDeStreamWalletManager : IWalletManager public interface IDeStreamWalletManager : IWalletManager
{ {
...@@ -8,5 +10,7 @@ ...@@ -8,5 +10,7 @@
void ProcessGenesisBlock(); void ProcessGenesisBlock();
HdAddress CreateAddress(WalletAccountReference accountReference); HdAddress CreateAddress(WalletAccountReference accountReference);
IEnumerable<string> GetOwnAddresses(WalletAccountReference accountReference);
} }
} }
\ No newline at end of file
...@@ -164,7 +164,7 @@ namespace Stratis.Bitcoin.Networks ...@@ -164,7 +164,7 @@ namespace Stratis.Bitcoin.Networks
new DNSSeedData("seed2.destream.io", "seed2.destream.io") new DNSSeedData("seed2.destream.io", "seed2.destream.io")
}; };
string[] seedNodes = {"13.68.198.162", "13.70.18.104"}; string[] seedNodes = {"46.101.9.205", "178.62.251.178", "134.209.225.244"};
this.SeedNodes = this.ConvertToNetworkAddresses(seedNodes, this.DefaultPort).ToList(); this.SeedNodes = this.ConvertToNetworkAddresses(seedNodes, this.DefaultPort).ToList();
......
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: node1-deny-traffic-except-platform
namespace: test
spec:
podSelector:
matchLabels:
app: node1
policyTypes:
- Ingress
- Egress
ingress:
- from:
- ipBlock:
cidr: 10.233.0.0/17
- from:
- ipBlock:
cidr: 151.101.112.249/32
egress:
- to:
- ipBlock:
cidr: 10.233.0.0/17
- to:
- ipBlock:
cidr: 151.101.112.249/32
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: node2-deny-traffic-except-platform
namespace: test
spec:
podSelector:
matchLabels:
app: node2
policyTypes:
- Ingress
- Egress
ingress:
- from:
- ipBlock:
cidr: 10.233.0.0/17
- from:
- ipBlock:
cidr: 151.101.112.249/32
egress:
- to:
- ipBlock:
cidr: 10.233.0.0/17
- to:
- ipBlock:
cidr: 151.101.112.249/32
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: node3-deny-traffic-except-platform
namespace: test
spec:
podSelector:
matchLabels:
app: node3
policyTypes:
- Ingress
- Egress
ingress:
- from:
- ipBlock:
cidr: 10.233.0.0/17
- from:
- ipBlock:
cidr: 151.101.112.249/32
egress:
- to:
- ipBlock:
cidr: 10.233.0.0/17
- to:
- ipBlock:
cidr: 151.101.112.249/32
---
kind: PersistentVolume
apiVersion: v1
metadata:
name: pv-node1
namespace: test
labels:
type: local
spec:
storageClassName: hostssd
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/mnt/node1"
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: pv-node1-claim
namespace: test
spec:
storageClassName: hostssd
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
---
kind: PersistentVolume
apiVersion: v1
metadata:
name: pv-node2
namespace: test
labels:
type: local
spec:
storageClassName: hostssd
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/mnt/node2"
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: pv-node2-claim
namespace: test
spec:
storageClassName: hostssd
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
---
kind: PersistentVolume
apiVersion: v1
metadata:
name: pv-node3
namespace: test
labels:
type: local
spec:
storageClassName: hostssd
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/mnt/node3"
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: pv-node3-claim
namespace: test
spec:
storageClassName: hostssd
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
---
apiVersion: v1
kind: Service
metadata:
name: node1
namespace: test
labels:
app: node1
spec:
ports:
- name: node1-api
port: 56833
targetPort: node1-api
selector:
app: node1
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: node1
labels:
app: node1
namespace: test
spec:
replicas: 1
revisionHistoryLimit: 2
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
selector:
matchLabels:
app: node1
template:
metadata:
labels:
app: node1
spec:
containers:
- name: node1
image: _IMAGE_NAME_:_VERSION_
command: ["dotnet"]
args: ["DeStream.DeStreamD.dll","-addnode=node2","-addnode=node3","IpRangeFiltering=false"]
ports:
- name: node1-api
containerPort: 56833
volumeMounts:
- name: pv-node1
mountPath: "/root/.destreamnode"
nodeName: node1
imagePullSecrets:
- name: registrypullsecret
volumes:
- name: pv-node1
persistentVolumeClaim:
claimName: pv-node1-claim
---
apiVersion: v1
kind: Service
metadata:
name: node2
namespace: test
labels:
app: node2
spec:
ports:
- name: node2-api
port: 56833
targetPort: node2-api
selector:
app: node2
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: node2
labels:
app: node2
namespace: test
spec:
replicas: 1
revisionHistoryLimit: 2
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
selector:
matchLabels:
app: node2
template:
metadata:
labels:
app: node2
spec:
containers:
- name: node2
image: _IMAGE_NAME_:_VERSION_
command: ["dotnet"]
args: ["DeStream.DeStreamD.dll","-addnode=node1","-addnode=node3","IpRangeFiltering=false"]
ports:
- name: node2-api
containerPort: 56833
volumeMounts:
- name: pv-node2
mountPath: "/root/.destreamnode"
nodeName: node2
imagePullSecrets:
- name: registrypullsecret
volumes:
- name: pv-node2
persistentVolumeClaim:
claimName: pv-node2-claim
---
apiVersion: v1
kind: Service
metadata:
name: node3
namespace: test
labels:
app: node3
spec:
ports:
- name: node3-api
port: 56833
targetPort: node3-api
selector:
app: node3
--- ---
apiVersion: apps/v1 apiVersion: apps/v1
kind: Deployment kind: Deployment
metadata: metadata:
name: node name: node3
labels: labels:
app: node app: node3
namespace: test namespace: test
spec: spec:
replicas: 3 replicas: 1
revisionHistoryLimit: 2 revisionHistoryLimit: 2
strategy: strategy:
type: Recreate type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
selector: selector:
matchLabels: matchLabels:
app: node app: node3
template: template:
metadata: metadata:
labels: labels:
app: node app: node3
spec: spec:
containers: containers:
- name: node - name: node3
image: _IMAGE_NAME_:_VERSION_ image: _IMAGE_NAME_:_VERSION_
command: ["dotnet"] command: ["dotnet"]
args: ["DeStream.DeStreamD.dll"] args: ["DeStream.DeStreamD.dll","-addnode=node1","-addnode=node2","IpRangeFiltering=false"]
ports: ports:
- name: node-api - name: node3-api
containerPort: 56833 containerPort: 56833
- name: node-svc
containerPort: 56864
volumeMounts: volumeMounts:
- name: pv-node-test - name: pv-node3
mountPath: "/root/.destreamnode" mountPath: "/root/.destreamnode"
nodeName: node3
imagePullSecrets: imagePullSecrets:
- name: registrypullsecret - name: registrypullsecret
volumes: volumes:
- name: pv-node-test - name: pv-node3
persistentVolumeClaim: persistentVolumeClaim:
claimName: pv-node-test-claim claimName: pv-node3-claim
\ No newline at end of file \ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment