2019-07-25 22:15:03 +00:00
|
|
|
package state
|
2019-07-20 21:57:31 +00:00
|
|
|
|
|
|
|
import (
|
2020-01-22 19:53:06 +00:00
|
|
|
"context"
|
2019-07-20 21:57:31 +00:00
|
|
|
"testing"
|
|
|
|
|
2019-12-19 20:13:17 +00:00
|
|
|
address "github.com/filecoin-project/go-address"
|
2019-10-18 04:47:41 +00:00
|
|
|
actors "github.com/filecoin-project/lotus/chain/actors"
|
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
2020-02-04 22:19:05 +00:00
|
|
|
cbor "github.com/ipfs/go-ipld-cbor"
|
2019-07-20 21:57:31 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func BenchmarkStateTreeSet(b *testing.B) {
|
2020-02-04 22:19:05 +00:00
|
|
|
cst := cbor.NewMemCborStore()
|
2019-07-20 21:57:31 +00:00
|
|
|
st, err := NewStateTree(cst)
|
|
|
|
if err != nil {
|
|
|
|
b.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
b.ResetTimer()
|
|
|
|
b.ReportAllocs()
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
a, err := address.NewIDAddress(uint64(i))
|
|
|
|
if err != nil {
|
|
|
|
b.Fatal(err)
|
|
|
|
}
|
|
|
|
err = st.SetActor(a, &types.Actor{
|
|
|
|
Balance: types.NewInt(1258812523),
|
|
|
|
Code: actors.StorageMinerCodeCid,
|
2019-10-21 18:12:11 +00:00
|
|
|
Head: actors.AccountCodeCid,
|
2019-07-20 21:57:31 +00:00
|
|
|
Nonce: uint64(i),
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
b.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkStateTreeSetFlush(b *testing.B) {
|
2020-02-04 22:19:05 +00:00
|
|
|
cst := cbor.NewMemCborStore()
|
2019-07-20 21:57:31 +00:00
|
|
|
st, err := NewStateTree(cst)
|
|
|
|
if err != nil {
|
|
|
|
b.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
b.ResetTimer()
|
|
|
|
b.ReportAllocs()
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
a, err := address.NewIDAddress(uint64(i))
|
|
|
|
if err != nil {
|
|
|
|
b.Fatal(err)
|
|
|
|
}
|
|
|
|
err = st.SetActor(a, &types.Actor{
|
|
|
|
Balance: types.NewInt(1258812523),
|
|
|
|
Code: actors.StorageMinerCodeCid,
|
2019-10-21 18:12:11 +00:00
|
|
|
Head: actors.AccountCodeCid,
|
2019-07-20 21:57:31 +00:00
|
|
|
Nonce: uint64(i),
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
b.Fatal(err)
|
|
|
|
}
|
2020-01-22 19:53:06 +00:00
|
|
|
if _, err := st.Flush(context.TODO()); err != nil {
|
2019-07-20 21:57:31 +00:00
|
|
|
b.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkStateTree10kGetActor(b *testing.B) {
|
2020-02-04 22:19:05 +00:00
|
|
|
cst := cbor.NewMemCborStore()
|
2019-07-20 21:57:31 +00:00
|
|
|
st, err := NewStateTree(cst)
|
|
|
|
if err != nil {
|
|
|
|
b.Fatal(err)
|
|
|
|
}
|
|
|
|
for i := 0; i < 10000; i++ {
|
|
|
|
a, err := address.NewIDAddress(uint64(i))
|
|
|
|
if err != nil {
|
|
|
|
b.Fatal(err)
|
|
|
|
}
|
|
|
|
err = st.SetActor(a, &types.Actor{
|
|
|
|
Balance: types.NewInt(1258812523 + uint64(i)),
|
|
|
|
Code: actors.StorageMinerCodeCid,
|
2019-10-21 18:12:11 +00:00
|
|
|
Head: actors.AccountCodeCid,
|
2019-07-20 21:57:31 +00:00
|
|
|
Nonce: uint64(i),
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
b.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-22 19:53:06 +00:00
|
|
|
if _, err := st.Flush(context.TODO()); err != nil {
|
2019-07-20 21:57:31 +00:00
|
|
|
b.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
b.ResetTimer()
|
|
|
|
b.ReportAllocs()
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
a, err := address.NewIDAddress(uint64(i % 10000))
|
|
|
|
if err != nil {
|
|
|
|
b.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = st.GetActor(a)
|
|
|
|
if err != nil {
|
|
|
|
b.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-09-23 09:52:53 +00:00
|
|
|
|
|
|
|
func TestSetCache(t *testing.T) {
|
2020-02-04 22:19:05 +00:00
|
|
|
cst := cbor.NewMemCborStore()
|
2019-09-23 09:52:53 +00:00
|
|
|
st, err := NewStateTree(cst)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
a, err := address.NewIDAddress(uint64(222))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
act := &types.Actor{
|
|
|
|
Balance: types.NewInt(0),
|
|
|
|
Code: actors.StorageMinerCodeCid,
|
2019-10-21 18:12:11 +00:00
|
|
|
Head: actors.AccountCodeCid,
|
2019-09-23 09:52:53 +00:00
|
|
|
Nonce: 0,
|
|
|
|
}
|
|
|
|
|
|
|
|
err = st.SetActor(a, act)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
act.Nonce = 1
|
|
|
|
|
|
|
|
outact, err := st.GetActor(a)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if outact.Nonce != act.Nonce {
|
|
|
|
t.Error("nonce didn't match")
|
|
|
|
}
|
|
|
|
}
|