Skip to content

Commit

Permalink
Fix some tests
Browse files Browse the repository at this point in the history
Signed-off-by: Jakub Sztandera <[email protected]>
  • Loading branch information
Jakub Sztandera committed Aug 6, 2020
1 parent 8af1910 commit d227d7c
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 76 deletions.
2 changes: 1 addition & 1 deletion chain/types/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (m *Message) ValidForBlockInclusion(minGas int64) error {
return xerrors.New("'Value' field cannot be greater than total filecoin supply")
}

if m.GasPrice.LessThan(big.Zero()) {
if m.GasFeeCap.LessThan(big.Zero()) {
return xerrors.New("'GasPrice' field cannot be negative")
}

Expand Down
160 changes: 86 additions & 74 deletions miner/miner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,25 +55,27 @@ func TestSelectNotOverLimited(t *testing.T) {
var goodMsgs []types.Message
for i := int64(0); i < build.BlockGasLimit/gasUsed+10; i++ {
goodMsgs = append(goodMsgs, types.Message{
From: a1,
To: a3,
Method: 4,
Nonce: uint64(1 + i),
Value: types.FromFil(0),
GasLimit: gasUsed + 1000,
GasPrice: types.NewInt(1),
From: a1,
To: a3,
Method: 4,
Nonce: uint64(1 + i),
Value: types.FromFil(0),
GasLimit: gasUsed + 1000,
GasPremium: types.NewInt(1),
GasFeeCap: types.NewInt(200),
})
}
var badMsgs []types.Message
for i := int64(0); i < build.BlockGasLimit/gasUsed+10; i++ {
badMsgs = append(badMsgs, types.Message{
From: a2,
To: a3,
Method: 4,
Nonce: uint64(1 + i),
Value: types.FromFil(0),
GasLimit: 10 * gasUsed,
GasPrice: types.NewInt(9),
From: a2,
To: a3,
Method: 4,
Nonce: uint64(1 + i),
Value: types.FromFil(0),
GasLimit: 10 * gasUsed,
GasPremium: types.NewInt(9),
GasFeeCap: types.NewInt(200),
})
}
outmsgs, err := SelectMessages(ctx, af, &types.TipSet{}, wrapMsgs(append(goodMsgs, badMsgs...)))
Expand Down Expand Up @@ -109,44 +111,49 @@ func TestMessageFiltering(t *testing.T) {

msgs := []types.Message{
{
From: a1,
To: a1,
Nonce: 3,
Value: types.FromFil(500),
GasLimit: 100_000_000,
GasPrice: types.NewInt(1),
From: a1,
To: a1,
Nonce: 3,
Value: types.FromFil(500),
GasLimit: 100_000_000,
GasPremium: types.NewInt(1),
GasFeeCap: types.NewInt(200),
},
{
From: a1,
To: a1,
Nonce: 4,
Value: types.FromFil(500),
GasLimit: 100_000_000,
GasPrice: types.NewInt(1),
From: a1,
To: a1,
Nonce: 4,
Value: types.FromFil(500),
GasLimit: 100_000_000,
GasPremium: types.NewInt(1),
GasFeeCap: types.NewInt(200),
},
{
From: a2,
To: a1,
Nonce: 1,
Value: types.FromFil(800),
GasLimit: 100_000_000,
GasPrice: types.NewInt(1),
From: a2,
To: a1,
Nonce: 1,
Value: types.FromFil(800),
GasLimit: 100_000_000,
GasPremium: types.NewInt(1),
GasFeeCap: types.NewInt(200),
},
{
From: a2,
To: a1,
Nonce: 0,
Value: types.FromFil(800),
GasLimit: 100_000_000,
GasPrice: types.NewInt(1),
From: a2,
To: a1,
Nonce: 0,
Value: types.FromFil(800),
GasLimit: 100_000_000,
GasPremium: types.NewInt(1),
GasFeeCap: types.NewInt(200),
},
{
From: a2,
To: a1,
Nonce: 2,
Value: types.FromFil(150),
GasLimit: 100,
GasPrice: types.NewInt(1),
From: a2,
To: a1,
Nonce: 2,
Value: types.FromFil(150),
GasLimit: 100,
GasPremium: types.NewInt(1),
GasFeeCap: types.NewInt(200),
},
}

Expand Down Expand Up @@ -193,44 +200,49 @@ func TestMessageFilteringSenderHopping(t *testing.T) {

msgs := []types.Message{
{
From: a1,
To: a1,
Nonce: 0,
Value: types.FromFil(500),
GasLimit: 2_000_000_000,
GasPrice: types.NewInt(100),
From: a1,
To: a1,
Nonce: 0,
Value: types.FromFil(500),
GasLimit: 2_000_000_000,
GasPremium: types.NewInt(100),
GasFeeCap: types.NewInt(200),
},
{
From: a1,
To: a1,
Nonce: 1,
Value: types.FromFil(500),
GasLimit: 2_000_000_000,
GasPrice: types.NewInt(1),
From: a1,
To: a1,
Nonce: 1,
Value: types.FromFil(500),
GasLimit: 2_000_000_000,
GasPremium: types.NewInt(1),
GasFeeCap: types.NewInt(200),
},
{
From: a2,
To: a1,
Nonce: 0,
Value: types.FromFil(1),
GasLimit: 1_000_000_000,
GasPrice: types.NewInt(10),
From: a2,
To: a1,
Nonce: 0,
Value: types.FromFil(1),
GasLimit: 1_000_000_000,
GasPremium: types.NewInt(10),
GasFeeCap: types.NewInt(200),
},
{
From: a2,
To: a1,
Nonce: 1,
Value: types.FromFil(1),
GasLimit: 1_000_000_000,
GasPrice: types.NewInt(1),
From: a2,
To: a1,
Nonce: 1,
Value: types.FromFil(1),
GasLimit: 1_000_000_000,
GasPremium: types.NewInt(1),
GasFeeCap: types.NewInt(200),
},
{
From: a2,
To: a1,
Nonce: 2,
Value: types.FromFil(1),
GasLimit: 100_000_000,
GasPrice: types.NewInt(1),
From: a2,
To: a1,
Nonce: 2,
Value: types.FromFil(1),
GasLimit: 100_000_000,
GasPremium: types.NewInt(1),
GasFeeCap: types.NewInt(200),
},
}

Expand Down
2 changes: 1 addition & 1 deletion miner/selectmessages.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func SelectMessages(ctx context.Context, al gasguess.ActorLookup, ts *types.TipS
log.Infow("failed to guess gas", "to", msg.Message.To, "method", msg.Message.Method, "err", err)
}

estimatedReward := big.Mul(types.NewInt(uint64(guessedGas)), msg.Message.GasPrice)
estimatedReward := big.Mul(types.NewInt(uint64(guessedGas)), msg.Message.GasPremium)

sm.gasReward = append(sm.gasReward, big.Add(sm.lastReward, estimatedReward))
sm.lastReward = sm.gasReward[len(sm.gasReward)-1]
Expand Down
7 changes: 7 additions & 0 deletions node/impl/full/mpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/messagepool"
"github.com/filecoin-project/lotus/chain/store"
"github.com/filecoin-project/lotus/chain/types"
Expand Down Expand Up @@ -109,6 +110,12 @@ func (a *MpoolAPI) MpoolPushMessage(ctx context.Context, msg *types.Message) (*t
}
msg.GasPrice = gasPrice
}
if msg.GasPremium == types.EmptyInt || types.BigCmp(msg.GasPremium, types.NewInt(0)) == 0 {
msg.GasPremium = types.NewInt(100)
}
if msg.GasFeeCap == types.EmptyInt || types.BigCmp(msg.GasFeeCap, types.NewInt(0)) == 0 {
msg.GasFeeCap = types.NewInt(10 * build.InitialBaseFee)
}

return a.Mpool.PushWithNonce(ctx, msg.From, func(from address.Address, nonce uint64) (*types.SignedMessage, error) {
msg.Nonce = nonce
Expand Down

0 comments on commit d227d7c

Please sign in to comment.