Skip to content

Commit 3ad08b8

Browse files
author
David Vorick
committed
Merge branch 'master' into benches
Conflicts: sync/trymutex_test.go
2 parents d0bcd4e + e50f57b commit 3ad08b8

File tree

107 files changed

+1618
-632
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+1618
-632
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ Version History
33

44
April 2017:
55

6+
v1.2.1 (patch release)
7+
- Faster host upgrading
8+
- Fix wallet bugs
9+
- Add siac command to cancel allowance
10+
611
v1.2.0 (minor release)
712
- Host overhaul
813
- Wallet overhaul

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# [![Sia Logo](http://sia.tech/img/svg/sia-green-logo.svg)](http://sia.tech) v1.2.0 (Blue Moon)
1+
# [![Sia Logo](http://sia.tech/img/svg/sia-green-logo.svg)](http://sia.tech) v1.2.1 (Blue Moon)
22

33
[![Build Status](https://travis-ci.org/NebulousLabs/Sia.svg?branch=master)](https://travis-ci.org/NebulousLabs/Sia)
44
[![GoDoc](https://godoc.org/github.com/NebulousLabs/Sia?status.svg)](https://godoc.org/github.com/NebulousLabs/Sia)

api/renter.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919

2020
var (
2121
// recommendedHosts is the number of hosts that the renter will form
22-
// contracts with if the value is not specified explicity in the call to
22+
// contracts with if the value is not specified explicitly in the call to
2323
// SetSettings.
2424
recommendedHosts = build.Select(build.Var{
2525
Standard: uint64(50),

api/server_helpers_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ func createServerTester(name string) (*serverTester, error) {
400400

401401
// createAuthenticatedServerTester creates an authenticated server tester
402402
// object that is ready for testing, including money in the wallet and all
403-
// modules initalized.
403+
// modules initialized.
404404
func createAuthenticatedServerTester(name string, password string) (*serverTester, error) {
405405
// createAuthenticatedServerTester should not get called during short
406406
// tests, as it takes a long time to run.

api/wallet_test.go

+119
Original file line numberDiff line numberDiff line change
@@ -833,3 +833,122 @@ func TestWalletReset(t *testing.T) {
833833
t.Error("wallet is not unlocked")
834834
}
835835
}
836+
837+
func TestWalletSiafunds(t *testing.T) {
838+
if testing.Short() {
839+
t.SkipNow()
840+
}
841+
t.Parallel()
842+
843+
walletPassword := "testpass"
844+
key := crypto.TwofishKey(crypto.HashObject(walletPassword))
845+
testdir := build.TempDir("api", t.Name())
846+
st, err := assembleServerTester(key, testdir)
847+
if err != nil {
848+
t.Fatal(err)
849+
}
850+
defer st.server.Close()
851+
852+
// mine some money
853+
for i := types.BlockHeight(0); i <= types.MaturityDelay; i++ {
854+
_, err := st.miner.AddBlock()
855+
if err != nil {
856+
t.Fatal(err)
857+
}
858+
}
859+
860+
// record transactions
861+
var wtg WalletTransactionsGET
862+
err = st.getAPI("/wallet/transactions?startheight=0&endheight=100", &wtg)
863+
if err != nil {
864+
t.Fatal(err)
865+
}
866+
numTxns := len(wtg.ConfirmedTransactions)
867+
868+
// load siafunds into the wallet
869+
siagPath, _ := filepath.Abs("../types/siag0of1of1.siakey")
870+
loadSiagValues := url.Values{}
871+
loadSiagValues.Set("keyfiles", siagPath)
872+
loadSiagValues.Set("encryptionpassword", walletPassword)
873+
err = st.stdPostAPI("/wallet/siagkey", loadSiagValues)
874+
if err != nil {
875+
t.Fatal(err)
876+
}
877+
878+
err = st.getAPI("/wallet/transactions?startheight=0&endheight=100", &wtg)
879+
if err != nil {
880+
t.Fatal(err)
881+
}
882+
if len(wtg.ConfirmedTransactions) != numTxns+1 {
883+
t.Errorf("expected %v transactions, got %v", numTxns+1, len(wtg.ConfirmedTransactions))
884+
}
885+
886+
// check balance
887+
var wg WalletGET
888+
err = st.getAPI("/wallet", &wg)
889+
if err != nil {
890+
t.Fatal(err)
891+
}
892+
if wg.SiafundBalance.Cmp64(2000) != 0 {
893+
t.Fatalf("bad siafund balance: expected %v, got %v", 2000, wg.SiafundBalance)
894+
}
895+
896+
// spend the siafunds into the wallet seed
897+
var wag WalletAddressGET
898+
err = st.getAPI("/wallet/address", &wag)
899+
if err != nil {
900+
t.Fatal(err)
901+
}
902+
sendSiafundsValues := url.Values{}
903+
sendSiafundsValues.Set("amount", "2000")
904+
sendSiafundsValues.Set("destination", wag.Address.String())
905+
err = st.stdPostAPI("/wallet/siafunds", sendSiafundsValues)
906+
if err != nil {
907+
t.Fatal(err)
908+
}
909+
910+
// Announce the host and form an allowance with it. This will result in a
911+
// siafund claim.
912+
err = st.announceHost()
913+
if err != nil {
914+
t.Fatal(err)
915+
}
916+
err = st.setHostStorage()
917+
if err != nil {
918+
t.Fatal(err)
919+
}
920+
err = st.acceptContracts()
921+
if err != nil {
922+
t.Fatal(err)
923+
}
924+
// mine a block so that the announcement makes it into the blockchain
925+
_, err = st.miner.AddBlock()
926+
if err != nil {
927+
t.Fatal(err)
928+
}
929+
930+
// form allowance
931+
allowanceValues := url.Values{}
932+
testFunds := "10000000000000000000000000000" // 10k SC
933+
testPeriod := "20"
934+
allowanceValues.Set("funds", testFunds)
935+
allowanceValues.Set("period", testPeriod)
936+
err = st.stdPostAPI("/renter", allowanceValues)
937+
if err != nil {
938+
t.Fatal(err)
939+
}
940+
941+
// mine a block so that the file contract makes it into the blockchain
942+
_, err = st.miner.AddBlock()
943+
if err != nil {
944+
t.Fatal(err)
945+
}
946+
// wallet should now have a claim balance
947+
err = st.getAPI("/wallet", &wg)
948+
if err != nil {
949+
t.Fatal(err)
950+
}
951+
if wg.SiacoinClaimBalance.IsZero() {
952+
t.Fatal("expected non-zero claim balance")
953+
}
954+
}

build/version.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77

88
const (
99
// Version is the current version of siad.
10-
Version = "1.2.0"
10+
Version = "1.2.1"
1111

1212
// MaxEncodedVersionLength is the maximum length of a version string encoded
1313
// with the encode package. 100 is much larger than any version number we send

doc/api/Renter.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ hosts
101101
// Duration of contracts formed. Must be nonzero.
102102
period // block height
103103
104-
// Renew window specifies how many blocks before the expriation of the current
104+
// Renew window specifies how many blocks before the expiration of the current
105105
// contracts the renter will wait before renewing the contracts. A smaller
106106
// renew window means that Sia must be run more frequently, but also means
107107
// fewer total transaction fees. Storage spending is not affected by the renew

doc/whitepaper.tex

+1-1
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ \section{Siafunds}
302302

303303
\section{Economics of Sia}
304304
The primary currency of Sia is the siacoin.
305-
The supply of siacoins will increase permanently, and all fresh supply will be given to miners as a block subisdy.
305+
The supply of siacoins will increase permanently, and all fresh supply will be given to miners as a block subsidy.
306306
The first block will have 300,000 coins minted.
307307
This number will decrease by 1 coin per block, until a minimum of 30,000 coins per block is reached.
308308
Following a target of 10 minutes between blocks, the annual growth in supply is:\\

modules/consensus/accept.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func (cs *ConsensusSet) validateHeaderAndBlock(tx dbTx, b types.Block) error {
6060
// Check that the timestamp is not too far in the past to be acceptable.
6161
minTimestamp := cs.blockRuleHelper.minimumValidChildTimestamp(blockMap, &parent)
6262

63-
return cs.blockValidator.ValidateBlock(b, minTimestamp, parent.ChildTarget, parent.Height+1)
63+
return cs.blockValidator.ValidateBlock(b, minTimestamp, parent.ChildTarget, parent.Height+1, cs.log)
6464
}
6565

6666
// checkHeaderTarget returns true if the header's ID meets the given target.

modules/consensus/accept_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"time"
88

99
"github.com/NebulousLabs/Sia/modules"
10+
"github.com/NebulousLabs/Sia/persist"
1011
"github.com/NebulousLabs/Sia/types"
1112
)
1213

@@ -163,7 +164,7 @@ func (brh mockBlockRuleHelper) minimumValidChildTimestamp(blockMap dbBucket, pb
163164

164165
// ValidateBlock stores the parameters it receives and returns the mock error
165166
// defined by mockBlockValidator.err.
166-
func (bv mockBlockValidator) ValidateBlock(b types.Block, minTimestamp types.Timestamp, target types.Target, height types.BlockHeight) error {
167+
func (bv mockBlockValidator) ValidateBlock(b types.Block, minTimestamp types.Timestamp, target types.Target, height types.BlockHeight, log *persist.Logger) error {
167168
validateBlockParamsGot = validateBlockParams{true, b, minTimestamp, target, height}
168169
return bv.err
169170
}

modules/consensus/block_validation.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"errors"
66

77
"github.com/NebulousLabs/Sia/modules"
8+
"github.com/NebulousLabs/Sia/persist"
89
"github.com/NebulousLabs/Sia/types"
910
)
1011

@@ -20,7 +21,7 @@ var (
2021
type blockValidator interface {
2122
// ValidateBlock validates a block against a minimum timestamp, a block
2223
// target, and a block height.
23-
ValidateBlock(types.Block, types.Timestamp, types.Target, types.BlockHeight) error
24+
ValidateBlock(types.Block, types.Timestamp, types.Target, types.BlockHeight, *persist.Logger) error
2425
}
2526

2627
// stdBlockValidator is the standard implementation of blockValidator.
@@ -63,7 +64,7 @@ func checkTarget(b types.Block, target types.Target) bool {
6364
// ValidateBlock validates a block against a minimum timestamp, a block target,
6465
// and a block height. Returns nil if the block is valid and an appropriate
6566
// error otherwise.
66-
func (bv stdBlockValidator) ValidateBlock(b types.Block, minTimestamp types.Timestamp, target types.Target, height types.BlockHeight) error {
67+
func (bv stdBlockValidator) ValidateBlock(b types.Block, minTimestamp types.Timestamp, target types.Target, height types.BlockHeight, log *persist.Logger) error {
6768
// Check that the timestamp is not too far in the past to be acceptable.
6869
if minTimestamp > b.Timestamp {
6970
return errEarlyTimestamp
@@ -75,7 +76,8 @@ func (bv stdBlockValidator) ValidateBlock(b types.Block, minTimestamp types.Time
7576
}
7677

7778
// Check that the block is below the size limit.
78-
if uint64(len(bv.marshaler.Marshal(b))) > types.BlockSizeLimit {
79+
blockSize := len(bv.marshaler.Marshal(b))
80+
if uint64(blockSize) > types.BlockSizeLimit {
7981
return errLargeBlock
8082
}
8183

@@ -98,5 +100,9 @@ func (bv stdBlockValidator) ValidateBlock(b types.Block, minTimestamp types.Time
98100
if b.Timestamp > bv.clock.Now()+types.FutureThreshold {
99101
return errFutureTimestamp
100102
}
103+
104+
if log != nil {
105+
log.Debugf("validated block at height %v, block size: %vB", height, blockSize)
106+
}
101107
return nil
102108
}

modules/consensus/block_validation_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func TestUnitValidateBlock(t *testing.T) {
7878
now: tt.now,
7979
},
8080
}
81-
err := blockValidator.ValidateBlock(b, tt.minTimestamp, types.RootDepth, 0)
81+
err := blockValidator.ValidateBlock(b, tt.minTimestamp, types.RootDepth, 0, nil)
8282
if err != tt.errWant {
8383
t.Errorf("%s: got %v, want %v", tt.msg, err, tt.errWant)
8484
}

modules/consensus/consensusdb.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func (cs *ConsensusSet) createConsensusDB(tx *bolt.Tx) error {
108108
UnlockHash: types.UnlockHash{},
109109
})
110110

111-
// Add the genesis block to the block strucutres - checksum must be taken
111+
// Add the genesis block to the block structures - checksum must be taken
112112
// after pushing the genesis block into the path.
113113
pushPath(tx, cs.blockRoot.Block.ID())
114114
if build.DEBUG {

modules/consensus/diffs.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ var (
1616
errDiffsNotGenerated = errors.New("applying diff set before generating errors")
1717
errInvalidSuccessor = errors.New("generating diffs for a block that's an invalid successsor to the current block")
1818
errNegativePoolAdjustment = errors.New("committing a siafund pool diff with a negative adjustment")
19-
errNonApplySiafundPoolDiff = errors.New("commiting a siafund pool diff that doesn't have the 'apply' direction")
19+
errNonApplySiafundPoolDiff = errors.New("committing a siafund pool diff that doesn't have the 'apply' direction")
2020
errRevertSiafundPoolDiffMismatch = errors.New("committing a siafund pool diff with an invalid 'adjusted' field")
2121
errWrongAppliedDiffSet = errors.New("applying a diff set that isn't the current block")
2222
errWrongRevertDiffSet = errors.New("reverting a diff set that isn't the current block")

modules/consensus/maintenance.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ func applyFileContractMaintenance(tx *bolt.Tx, pb *processedBlock) {
184184
}
185185

186186
// applyMaintenance applies block-level alterations to the consensus set.
187-
// Maintenance is applied after all of the transcations for the block have been
187+
// Maintenance is applied after all of the transactions for the block have been
188188
// applied.
189189
func applyMaintenance(tx *bolt.Tx, pb *processedBlock) {
190190
applyMinerPayouts(tx, pb)

modules/consensus/processedblock.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func (cs *ConsensusSet) setChildTarget(blockMap *bolt.Bucket, pb *processedBlock
120120
}
121121

122122
// newChild creates a blockNode from a block and adds it to the parent's set of
123-
// children. The new node is also returned. It necessairly modifies the database
123+
// children. The new node is also returned. It necessarily modifies the database
124124
func (cs *ConsensusSet) newChild(tx *bolt.Tx, pb *processedBlock, b types.Block) *processedBlock {
125125
// Create the child node.
126126
childID := b.ID()

0 commit comments

Comments
 (0)