Skip to content

Commit

Permalink
Merge pull request #113 from SiaFoundation/nate/new-network-params
Browse files Browse the repository at this point in the history
Support MaturityDelay and BlockTime network params
  • Loading branch information
n8maninger authored Oct 23, 2024
2 parents d60e3e7 + 29cb039 commit 6383fa9
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 21 deletions.
4 changes: 4 additions & 0 deletions chain/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ func Mainnet() (*consensus.Network, types.Block) {
InitialCoinbase: types.Siacoins(300000),
MinimumCoinbase: types.Siacoins(30000),
InitialTarget: types.BlockID{4: 32},
BlockInterval: 10 * time.Minute,
MaturityDelay: 144,
}
n.HardforkDevAddr.Height = 10000
n.HardforkDevAddr.OldAddress = parseAddr("addr:7d0c44f7664e2d34e53efde0661a6f628ec9264785ae8e3cd7c973e8d190c3c97b5e3ecbc567")
Expand Down Expand Up @@ -115,6 +117,8 @@ func TestnetZen() (*consensus.Network, types.Block) {
InitialCoinbase: types.Siacoins(300000),
MinimumCoinbase: types.Siacoins(300000),
InitialTarget: types.BlockID{3: 1},
BlockInterval: 10 * time.Minute,
MaturityDelay: 144,
}

n.HardforkDevAddr.Height = 1
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ toolchain go1.23.2

require (
go.etcd.io/bbolt v1.3.11
go.sia.tech/core v0.4.7
go.sia.tech/core v0.5.0
go.uber.org/zap v1.27.0
golang.org/x/crypto v0.28.0
lukechampine.com/frand v1.5.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKs
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
go.etcd.io/bbolt v1.3.11 h1:yGEzV1wPz2yVCLsD8ZAiGHhHVlczyC9d1rP43/VCRJ0=
go.etcd.io/bbolt v1.3.11/go.mod h1:dksAq7YMXoljX0xu6VF5DMZGbhYYoLUalEiSySYAS4I=
go.sia.tech/core v0.4.7 h1:UAyErZ3nk5/7N0gIG0OEEJJrxh7ru8lgGLlaNtT/Jq0=
go.sia.tech/core v0.4.7/go.mod h1:j2Ke8ihV8or7d2VDrFZWcCkwSVHO0DNMQJAGs9Qop2M=
go.sia.tech/core v0.5.0 h1:feLC7DSCF+PhU157s/94106hFKyiGrGQ9HC3/dF/l7E=
go.sia.tech/core v0.5.0/go.mod h1:P3C1BWa/7J4XgdzWuaYHBvLo2RzZ0UBaJM4TG1GWB2g=
go.sia.tech/mux v1.3.0 h1:hgR34IEkqvfBKUJkAzGi31OADeW2y7D6Bmy/Jcbop9c=
go.sia.tech/mux v1.3.0/go.mod h1:I46++RD4beqA3cW9Xm9SwXbezwPqLvHhVs9HLpDtt58=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
Expand Down
10 changes: 8 additions & 2 deletions testutil/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ func Network() (*consensus.Network, types.Block) {
// use a modified version of Zen
n, genesisBlock := chain.TestnetZen()
n.InitialTarget = types.BlockID{0xFF}
n.BlockInterval = time.Second
n.MaturityDelay = 5

n.HardforkDevAddr.Height = 1
n.HardforkTax.Height = 1
n.HardforkStorageProof.Height = 1
Expand All @@ -31,14 +34,17 @@ func V2Network() (*consensus.Network, types.Block) {
// use a modified version of Zen
n, genesisBlock := chain.TestnetZen()
n.InitialTarget = types.BlockID{0xFF}
n.BlockInterval = time.Second
n.MaturityDelay = 5

n.HardforkDevAddr.Height = 1
n.HardforkTax.Height = 1
n.HardforkStorageProof.Height = 1
n.HardforkOak.Height = 1
n.HardforkASIC.Height = 1
n.HardforkFoundation.Height = 1
n.HardforkV2.AllowHeight = 100
n.HardforkV2.RequireHeight = 110
n.HardforkV2.AllowHeight = 1
n.HardforkV2.RequireHeight = 1
return n, genesisBlock
}

Expand Down
26 changes: 10 additions & 16 deletions wallet/wallet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1052,9 +1052,7 @@ func TestReorgV2(t *testing.T) {
ws := testutil.NewEphemeralWalletStore()

// create chain store
network, genesis := testutil.Network()
network.HardforkV2.AllowHeight = 10
network.HardforkV2.RequireHeight = 20
network, genesis := testutil.V2Network()
cs, genesisState, err := chain.NewDBStore(chain.NewMemDB(), network, genesis)
if err != nil {
t.Fatal(err)
Expand All @@ -1077,8 +1075,6 @@ func TestReorgV2(t *testing.T) {
// mine a block to fund the wallet
mineAndSync(t, cm, ws, w, w.Address(), 1)
maturityHeight := genesisState.MaturityHeight()
// mine until the require height
mineAndSync(t, cm, ws, w, types.VoidAddress, network.HardforkV2.RequireHeight-cm.Tip().Height)

// check that the wallet has a single event
if events, err := w.Events(0, 100); err != nil {
Expand Down Expand Up @@ -1407,7 +1403,7 @@ func TestSingleAddressWalletEventTypes(t *testing.T) {

network, genesisBlock := testutil.V2Network()
// raise the require height to test v1 events
network.HardforkV2.RequireHeight = 250
network.HardforkV2.RequireHeight = 100
store, genesisState, err := chain.NewDBStore(bdb, network, genesisBlock)
if err != nil {
t.Fatal(err)
Expand All @@ -1423,7 +1419,7 @@ func TestSingleAddressWalletEventTypes(t *testing.T) {

// miner payout event
mineAndSync(t, cm, ws, wm, addr, 1)
assertEvent(t, wm, types.Hash256(cm.Tip().ID.MinerOutputID(0)), wallet.EventTypeMinerPayout, genesisState.BlockReward(), types.ZeroCurrency, 145)
assertEvent(t, wm, types.Hash256(cm.Tip().ID.MinerOutputID(0)), wallet.EventTypeMinerPayout, genesisState.BlockReward(), types.ZeroCurrency, genesisState.MaturityHeight())

// mine until the payout matures
mineAndSync(t, cm, ws, wm, types.VoidAddress, genesisState.MaturityHeight()-cm.Tip().Height+1)
Expand Down Expand Up @@ -1489,7 +1485,7 @@ func TestSingleAddressWalletEventTypes(t *testing.T) {

// mine until the contract expires to trigger the resolution event
mineAndSync(t, cm, ws, wm, types.VoidAddress, fc.WindowEnd-cm.Tip().Height)
assertEvent(t, wm, types.Hash256(txn.FileContractID(0).MissedOutputID(0)), wallet.EventTypeV1ContractResolution, missedPayout, types.ZeroCurrency, fc.WindowEnd+144)
assertEvent(t, wm, types.Hash256(txn.FileContractID(0).MissedOutputID(0)), wallet.EventTypeV1ContractResolution, missedPayout, types.ZeroCurrency, fc.WindowEnd+network.MaturityDelay)
})

t.Run("v2 transaction", func(t *testing.T) {
Expand Down Expand Up @@ -1587,7 +1583,7 @@ func TestSingleAddressWalletEventTypes(t *testing.T) {
}
// mine a block to confirm the resolution
mineAndSync(t, cm, ws, wm, types.VoidAddress, 1)
assertEvent(t, wm, types.Hash256(types.FileContractID(fce.ID).V2RenterOutputID()), wallet.EventTypeV2ContractResolution, renterPayout, types.ZeroCurrency, cm.Tip().Height+144)
assertEvent(t, wm, types.Hash256(types.FileContractID(fce.ID).V2RenterOutputID()), wallet.EventTypeV2ContractResolution, renterPayout, types.ZeroCurrency, cm.Tip().Height+network.MaturityDelay)
})

t.Run("v2 contract resolution - storage proof", func(t *testing.T) {
Expand Down Expand Up @@ -1670,7 +1666,7 @@ func TestSingleAddressWalletEventTypes(t *testing.T) {
}
// mine a block to confirm the resolution
mineAndSync(t, cm, ws, wm, types.VoidAddress, 1)
assertEvent(t, wm, types.Hash256(types.FileContractID(fce.ID).V2HostOutputID()), wallet.EventTypeV2ContractResolution, renterPayout, types.ZeroCurrency, cm.Tip().Height+144)
assertEvent(t, wm, types.Hash256(types.FileContractID(fce.ID).V2HostOutputID()), wallet.EventTypeV2ContractResolution, renterPayout, types.ZeroCurrency, cm.Tip().Height+network.MaturityDelay)
})

t.Run("v2 contract resolution - renewal", func(t *testing.T) {
Expand Down Expand Up @@ -1794,7 +1790,7 @@ func TestSingleAddressWalletEventTypes(t *testing.T) {
}
// mine a block to confirm the renewal
mineAndSync(t, cm, ws, wm, types.VoidAddress, 1)
assertEvent(t, wm, types.Hash256(types.FileContractID(fce.ID).V2RenterOutputID()), wallet.EventTypeV2ContractResolution, renterPayout, types.ZeroCurrency, cm.Tip().Height+144)
assertEvent(t, wm, types.Hash256(types.FileContractID(fce.ID).V2RenterOutputID()), wallet.EventTypeV2ContractResolution, renterPayout, types.ZeroCurrency, cm.Tip().Height+network.MaturityDelay)
})

t.Run("v2 contract resolution - finalization", func(t *testing.T) {
Expand Down Expand Up @@ -1860,10 +1856,8 @@ func TestSingleAddressWalletEventTypes(t *testing.T) {
finalRevision := fce.V2FileContract
finalRevision.RevisionNumber = math.MaxUint64
finalRevisionSigHash := cm.TipState().ContractSigHash(finalRevision)
finalRevision.RenterSignature = pk.SignHash(finalRevisionSigHash)
finalRevision.HostSignature = pk.SignHash(finalRevisionSigHash)
// create a renewal
finalization := types.V2FileContractFinalization(finalRevision)
finalization := types.V2FileContractFinalization(pk.SignHash(finalRevisionSigHash))

// create the renewal transaction
resolutionTxn := types.V2Transaction{
Expand All @@ -1881,7 +1875,7 @@ func TestSingleAddressWalletEventTypes(t *testing.T) {
}
// mine a block to confirm the renewal
mineAndSync(t, cm, ws, wm, types.VoidAddress, 1)
assertEvent(t, wm, types.Hash256(types.FileContractID(fce.ID).V2RenterOutputID()), wallet.EventTypeV2ContractResolution, renterPayout, types.ZeroCurrency, cm.Tip().Height+144)
assertEvent(t, wm, types.Hash256(types.FileContractID(fce.ID).V2RenterOutputID()), wallet.EventTypeV2ContractResolution, renterPayout, types.ZeroCurrency, cm.Tip().Height+network.MaturityDelay)
})
}

Expand Down Expand Up @@ -1910,7 +1904,7 @@ func TestV2TPoolRace(t *testing.T) {
// fund the wallet
mineAndSync(t, cm, ws, w, w.Address(), 1)
// mine until one utxo is mature
mineAndSync(t, cm, ws, w, types.VoidAddress, 144)
mineAndSync(t, cm, ws, w, types.VoidAddress, network.MaturityDelay)

// create a transaction that creates an ephemeral output with 1000 SC
setupTxn := types.V2Transaction{
Expand Down

0 comments on commit 6383fa9

Please sign in to comment.