mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-30 15:56:30 +00:00
Sentinel refactor (#8296)
1. changes sentinel to use an http-like interface 2. moves hexutil, crypto/blake2b, metrics packages to erigon-lib
This commit is contained in:
parent
0ac11d0c94
commit
436493350e
@ -1137,7 +1137,7 @@ func TestUnpackRevert(t *testing.T) {
|
||||
}
|
||||
for index, c := range cases {
|
||||
t.Run(fmt.Sprintf("case %d", index), func(t *testing.T) {
|
||||
got, err := UnpackRevert(common.Hex2Bytes(c.input))
|
||||
got, err := UnpackRevert(libcommon.Hex2Bytes(c.input))
|
||||
if c.expectErr != nil {
|
||||
if err == nil {
|
||||
t.Fatalf("Expected non-nil error")
|
||||
|
@ -467,7 +467,7 @@ func TestSimulatedBackend_EstimateGas(t *testing.T) {
|
||||
Gas: 0,
|
||||
GasPrice: u256.Num0,
|
||||
Value: nil,
|
||||
Data: common.Hex2Bytes("d8b98391"),
|
||||
Data: libcommon.Hex2Bytes("d8b98391"),
|
||||
}, 0, errors.New("execution reverted: revert reason"), "0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000d72657665727420726561736f6e00000000000000000000000000000000000000"},
|
||||
|
||||
{"PureRevert", ethereum.CallMsg{
|
||||
@ -476,7 +476,7 @@ func TestSimulatedBackend_EstimateGas(t *testing.T) {
|
||||
Gas: 0,
|
||||
GasPrice: u256.Num0,
|
||||
Value: nil,
|
||||
Data: common.Hex2Bytes("aa8b1d30"),
|
||||
Data: libcommon.Hex2Bytes("aa8b1d30"),
|
||||
}, 0, errors.New("execution reverted"), nil},
|
||||
|
||||
{"OOG", ethereum.CallMsg{
|
||||
@ -485,7 +485,7 @@ func TestSimulatedBackend_EstimateGas(t *testing.T) {
|
||||
Gas: 100000,
|
||||
GasPrice: u256.Num0,
|
||||
Value: nil,
|
||||
Data: common.Hex2Bytes("50f6fe34"),
|
||||
Data: libcommon.Hex2Bytes("50f6fe34"),
|
||||
}, 0, errors.New("gas required exceeds allowance (100000)"), nil},
|
||||
|
||||
{"Assert", ethereum.CallMsg{
|
||||
@ -494,7 +494,7 @@ func TestSimulatedBackend_EstimateGas(t *testing.T) {
|
||||
Gas: 100000,
|
||||
GasPrice: u256.Num0,
|
||||
Value: nil,
|
||||
Data: common.Hex2Bytes("b9b046f9"),
|
||||
Data: libcommon.Hex2Bytes("b9b046f9"),
|
||||
}, 0, errors.New("invalid opcode: INVALID"), nil},
|
||||
|
||||
{"Valid", ethereum.CallMsg{
|
||||
@ -503,7 +503,7 @@ func TestSimulatedBackend_EstimateGas(t *testing.T) {
|
||||
Gas: 100000,
|
||||
GasPrice: u256.Num0,
|
||||
Value: nil,
|
||||
Data: common.Hex2Bytes("e09fface"),
|
||||
Data: libcommon.Hex2Bytes("e09fface"),
|
||||
}, 21275, nil, nil},
|
||||
}
|
||||
for _, c := range cases {
|
||||
|
@ -18,6 +18,7 @@ package bind_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/ledgerwatch/erigon-lib/common/hexutil"
|
||||
"math/big"
|
||||
"reflect"
|
||||
"strings"
|
||||
@ -28,7 +29,6 @@ import (
|
||||
ethereum "github.com/ledgerwatch/erigon"
|
||||
"github.com/ledgerwatch/erigon/accounts/abi"
|
||||
"github.com/ledgerwatch/erigon/accounts/abi/bind"
|
||||
"github.com/ledgerwatch/erigon/common/hexutil"
|
||||
"github.com/ledgerwatch/erigon/core/types"
|
||||
"github.com/ledgerwatch/erigon/crypto"
|
||||
"github.com/ledgerwatch/erigon/rlp"
|
||||
|
@ -185,25 +185,25 @@ func TestPackNumber(t *testing.T) {
|
||||
packed []byte
|
||||
}{
|
||||
// Protocol limits
|
||||
{reflect.ValueOf(0), common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000000")},
|
||||
{reflect.ValueOf(1), common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000001")},
|
||||
{reflect.ValueOf(-1), common.Hex2Bytes("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")},
|
||||
{reflect.ValueOf(0), libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000000")},
|
||||
{reflect.ValueOf(1), libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000001")},
|
||||
{reflect.ValueOf(-1), libcommon.Hex2Bytes("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")},
|
||||
|
||||
// Type corner cases
|
||||
{reflect.ValueOf(uint8(math.MaxUint8)), common.Hex2Bytes("00000000000000000000000000000000000000000000000000000000000000ff")},
|
||||
{reflect.ValueOf(uint16(math.MaxUint16)), common.Hex2Bytes("000000000000000000000000000000000000000000000000000000000000ffff")},
|
||||
{reflect.ValueOf(uint32(math.MaxUint32)), common.Hex2Bytes("00000000000000000000000000000000000000000000000000000000ffffffff")},
|
||||
{reflect.ValueOf(uint64(math.MaxUint64)), common.Hex2Bytes("000000000000000000000000000000000000000000000000ffffffffffffffff")},
|
||||
{reflect.ValueOf(uint8(math.MaxUint8)), libcommon.Hex2Bytes("00000000000000000000000000000000000000000000000000000000000000ff")},
|
||||
{reflect.ValueOf(uint16(math.MaxUint16)), libcommon.Hex2Bytes("000000000000000000000000000000000000000000000000000000000000ffff")},
|
||||
{reflect.ValueOf(uint32(math.MaxUint32)), libcommon.Hex2Bytes("00000000000000000000000000000000000000000000000000000000ffffffff")},
|
||||
{reflect.ValueOf(uint64(math.MaxUint64)), libcommon.Hex2Bytes("000000000000000000000000000000000000000000000000ffffffffffffffff")},
|
||||
|
||||
{reflect.ValueOf(int8(math.MaxInt8)), common.Hex2Bytes("000000000000000000000000000000000000000000000000000000000000007f")},
|
||||
{reflect.ValueOf(int16(math.MaxInt16)), common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000007fff")},
|
||||
{reflect.ValueOf(int32(math.MaxInt32)), common.Hex2Bytes("000000000000000000000000000000000000000000000000000000007fffffff")},
|
||||
{reflect.ValueOf(int64(math.MaxInt64)), common.Hex2Bytes("0000000000000000000000000000000000000000000000007fffffffffffffff")},
|
||||
{reflect.ValueOf(int8(math.MaxInt8)), libcommon.Hex2Bytes("000000000000000000000000000000000000000000000000000000000000007f")},
|
||||
{reflect.ValueOf(int16(math.MaxInt16)), libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000007fff")},
|
||||
{reflect.ValueOf(int32(math.MaxInt32)), libcommon.Hex2Bytes("000000000000000000000000000000000000000000000000000000007fffffff")},
|
||||
{reflect.ValueOf(int64(math.MaxInt64)), libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000007fffffffffffffff")},
|
||||
|
||||
{reflect.ValueOf(int8(math.MinInt8)), common.Hex2Bytes("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff80")},
|
||||
{reflect.ValueOf(int16(math.MinInt16)), common.Hex2Bytes("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8000")},
|
||||
{reflect.ValueOf(int32(math.MinInt32)), common.Hex2Bytes("ffffffffffffffffffffffffffffffffffffffffffffffffffffffff80000000")},
|
||||
{reflect.ValueOf(int64(math.MinInt64)), common.Hex2Bytes("ffffffffffffffffffffffffffffffffffffffffffffffff8000000000000000")},
|
||||
{reflect.ValueOf(int8(math.MinInt8)), libcommon.Hex2Bytes("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff80")},
|
||||
{reflect.ValueOf(int16(math.MinInt16)), libcommon.Hex2Bytes("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8000")},
|
||||
{reflect.ValueOf(int32(math.MinInt32)), libcommon.Hex2Bytes("ffffffffffffffffffffffffffffffffffffffffffffffffffffffff80000000")},
|
||||
{reflect.ValueOf(int64(math.MinInt64)), libcommon.Hex2Bytes("ffffffffffffffffffffffffffffffffffffffffffffffff8000000000000000")},
|
||||
}
|
||||
for i, tt := range tests {
|
||||
packed := packNum(tt.value)
|
||||
|
@ -20,8 +20,6 @@ import (
|
||||
"math/big"
|
||||
|
||||
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
||||
|
||||
"github.com/ledgerwatch/erigon/common"
|
||||
)
|
||||
|
||||
type packUnpackTest struct {
|
||||
@ -378,7 +376,7 @@ var packUnpackTests = []packUnpackTest{
|
||||
packed: "0000000000000000000000000000000000000000000000000000000000000020" +
|
||||
"0000000000000000000000000000000000000000000000000000000000000020" +
|
||||
"0100000000000000000000000000000000000000000000000000000000000000",
|
||||
unpacked: common.Hex2Bytes("0100000000000000000000000000000000000000000000000000000000000000"),
|
||||
unpacked: libcommon.Hex2Bytes("0100000000000000000000000000000000000000000000000000000000000000"),
|
||||
},
|
||||
{
|
||||
def: `[{"type": "bytes32"}]`,
|
||||
|
@ -258,8 +258,8 @@ func TestUnpackIntoInterfaceSetDynamicArrayOutput(t *testing.T) {
|
||||
}
|
||||
|
||||
var (
|
||||
marshalledReturn32 = common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000230783132333435363738393000000000000000000000000000000000000000003078303938373635343332310000000000000000000000000000000000000000")
|
||||
marshalledReturn15 = common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000230783031323334350000000000000000000000000000000000000000000000003078393837363534000000000000000000000000000000000000000000000000")
|
||||
marshalledReturn32 = libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000230783132333435363738393000000000000000000000000000000000000000003078303938373635343332310000000000000000000000000000000000000000")
|
||||
marshalledReturn15 = libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000230783031323334350000000000000000000000000000000000000000000000003078393837363534000000000000000000000000000000000000000000000000")
|
||||
|
||||
out32 [][32]byte
|
||||
out15 [][15]byte
|
||||
@ -273,11 +273,11 @@ func TestUnpackIntoInterfaceSetDynamicArrayOutput(t *testing.T) {
|
||||
if len(out32) != 2 {
|
||||
t.Fatalf("expected array with 2 values, got %d", len(out32))
|
||||
}
|
||||
expected := common.Hex2Bytes("3078313233343536373839300000000000000000000000000000000000000000")
|
||||
expected := libcommon.Hex2Bytes("3078313233343536373839300000000000000000000000000000000000000000")
|
||||
if !bytes.Equal(out32[0][:], expected) {
|
||||
t.Errorf("expected %x, got %x\n", expected, out32[0])
|
||||
}
|
||||
expected = common.Hex2Bytes("3078303938373635343332310000000000000000000000000000000000000000")
|
||||
expected = libcommon.Hex2Bytes("3078303938373635343332310000000000000000000000000000000000000000")
|
||||
if !bytes.Equal(out32[1][:], expected) {
|
||||
t.Errorf("expected %x, got %x\n", expected, out32[1])
|
||||
}
|
||||
@ -290,11 +290,11 @@ func TestUnpackIntoInterfaceSetDynamicArrayOutput(t *testing.T) {
|
||||
if len(out15) != 2 {
|
||||
t.Fatalf("expected array with 2 values, got %d", len(out15))
|
||||
}
|
||||
expected = common.Hex2Bytes("307830313233343500000000000000")
|
||||
expected = libcommon.Hex2Bytes("307830313233343500000000000000")
|
||||
if !bytes.Equal(out15[0][:], expected) {
|
||||
t.Errorf("expected %x, got %x\n", expected, out15[0])
|
||||
}
|
||||
expected = common.Hex2Bytes("307839383736353400000000000000")
|
||||
expected = libcommon.Hex2Bytes("307839383736353400000000000000")
|
||||
if !bytes.Equal(out15[1][:], expected) {
|
||||
t.Errorf("expected %x, got %x\n", expected, out15[1])
|
||||
}
|
||||
@ -314,9 +314,9 @@ func methodMultiReturn(require *require.Assertions) (ABI, []byte, methodMultiOut
|
||||
require.NoError(err)
|
||||
// using buff to make the code readable
|
||||
buff := new(bytes.Buffer)
|
||||
buff.Write(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000001"))
|
||||
buff.Write(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000040"))
|
||||
buff.Write(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000005"))
|
||||
buff.Write(libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000001"))
|
||||
buff.Write(libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000040"))
|
||||
buff.Write(libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000005"))
|
||||
buff.Write(common.RightPadBytes([]byte(expected.String), 32))
|
||||
return abi, buff.Bytes(), expected
|
||||
}
|
||||
@ -402,8 +402,8 @@ func TestMultiReturnWithArray(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
buff := new(bytes.Buffer)
|
||||
buff.Write(common.Hex2Bytes("000000000000000000000000000000000000000000000000000000000000000900000000000000000000000000000000000000000000000000000000000000090000000000000000000000000000000000000000000000000000000000000009"))
|
||||
buff.Write(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000008"))
|
||||
buff.Write(libcommon.Hex2Bytes("000000000000000000000000000000000000000000000000000000000000000900000000000000000000000000000000000000000000000000000000000000090000000000000000000000000000000000000000000000000000000000000009"))
|
||||
buff.Write(libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000008"))
|
||||
|
||||
ret1, ret1Exp := new([3]uint64), [3]uint64{9, 9, 9}
|
||||
ret2, ret2Exp := new(uint64), uint64(8)
|
||||
@ -425,7 +425,7 @@ func TestMultiReturnWithStringArray(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
buff := new(bytes.Buffer)
|
||||
buff.Write(common.Hex2Bytes("000000000000000000000000000000000000000000000000000000005c1b78ea0000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000001a055690d9db80000000000000000000000000000ab1257528b3782fb40d7ed5f72e624b744dffb2f00000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000008457468657265756d000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001048656c6c6f2c20457468657265756d2100000000000000000000000000000000"))
|
||||
buff.Write(libcommon.Hex2Bytes("000000000000000000000000000000000000000000000000000000005c1b78ea0000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000001a055690d9db80000000000000000000000000000ab1257528b3782fb40d7ed5f72e624b744dffb2f00000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000008457468657265756d000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001048656c6c6f2c20457468657265756d2100000000000000000000000000000000"))
|
||||
temp, _ := big.NewInt(0).SetString("30000000000000000000", 10)
|
||||
ret1, ret1Exp := new([3]*big.Int), [3]*big.Int{big.NewInt(1545304298), big.NewInt(6), temp}
|
||||
ret2, ret2Exp := new(libcommon.Address), libcommon.HexToAddress("ab1257528b3782fb40d7ed5f72e624b744dffb2f")
|
||||
@ -455,18 +455,18 @@ func TestMultiReturnWithStringSlice(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
buff := new(bytes.Buffer)
|
||||
buff.Write(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000040")) // output[0] offset
|
||||
buff.Write(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000120")) // output[1] offset
|
||||
buff.Write(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000002")) // output[0] length
|
||||
buff.Write(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000040")) // output[0][0] offset
|
||||
buff.Write(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000080")) // output[0][1] offset
|
||||
buff.Write(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000008")) // output[0][0] length
|
||||
buff.Write(common.Hex2Bytes("657468657265756d000000000000000000000000000000000000000000000000")) // output[0][0] value
|
||||
buff.Write(common.Hex2Bytes("000000000000000000000000000000000000000000000000000000000000000b")) // output[0][1] length
|
||||
buff.Write(common.Hex2Bytes("676f2d657468657265756d000000000000000000000000000000000000000000")) // output[0][1] value
|
||||
buff.Write(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000002")) // output[1] length
|
||||
buff.Write(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000064")) // output[1][0] value
|
||||
buff.Write(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000065")) // output[1][1] value
|
||||
buff.Write(libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000040")) // output[0] offset
|
||||
buff.Write(libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000120")) // output[1] offset
|
||||
buff.Write(libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000002")) // output[0] length
|
||||
buff.Write(libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000040")) // output[0][0] offset
|
||||
buff.Write(libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000080")) // output[0][1] offset
|
||||
buff.Write(libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000008")) // output[0][0] length
|
||||
buff.Write(libcommon.Hex2Bytes("657468657265756d000000000000000000000000000000000000000000000000")) // output[0][0] value
|
||||
buff.Write(libcommon.Hex2Bytes("000000000000000000000000000000000000000000000000000000000000000b")) // output[0][1] length
|
||||
buff.Write(libcommon.Hex2Bytes("676f2d657468657265756d000000000000000000000000000000000000000000")) // output[0][1] value
|
||||
buff.Write(libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000002")) // output[1] length
|
||||
buff.Write(libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000064")) // output[1][0] value
|
||||
buff.Write(libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000065")) // output[1][1] value
|
||||
ret1, ret1Exp := new([]string), []string{"ethereum", "go-ethereum"}
|
||||
ret2, ret2Exp := new([]*big.Int), []*big.Int{big.NewInt(100), big.NewInt(101)}
|
||||
if err := abi.UnpackIntoInterface(&[]interface{}{ret1, ret2}, "multi", buff.Bytes()); err != nil {
|
||||
@ -493,14 +493,14 @@ func TestMultiReturnWithDeeplyNestedArray(t *testing.T) {
|
||||
buff := new(bytes.Buffer)
|
||||
// construct the test array, each 3 char element is joined with 61 '0' chars,
|
||||
// to from the ((3 + 61) * 0.5) = 32 byte elements in the array.
|
||||
buff.Write(common.Hex2Bytes(strings.Join([]string{
|
||||
buff.Write(libcommon.Hex2Bytes(strings.Join([]string{
|
||||
"", //empty, to apply the 61-char separator to the first element as well.
|
||||
"111", "112", "113", "121", "122", "123",
|
||||
"211", "212", "213", "221", "222", "223",
|
||||
"311", "312", "313", "321", "322", "323",
|
||||
"411", "412", "413", "421", "422", "423",
|
||||
}, "0000000000000000000000000000000000000000000000000000000000000")))
|
||||
buff.Write(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000009876"))
|
||||
buff.Write(libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000009876"))
|
||||
|
||||
ret1, ret1Exp := new([4][2][3]uint64), [4][2][3]uint64{
|
||||
{{0x111, 0x112, 0x113}, {0x121, 0x122, 0x123}},
|
||||
@ -539,14 +539,14 @@ func TestUnmarshal(t *testing.T) {
|
||||
buff := new(bytes.Buffer)
|
||||
|
||||
// marshall mixed bytes (mixedBytes)
|
||||
p0, p0Exp := []byte{}, common.Hex2Bytes("01020000000000000000")
|
||||
p1, p1Exp := [32]byte{}, common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000ddeeff")
|
||||
p0, p0Exp := []byte{}, libcommon.Hex2Bytes("01020000000000000000")
|
||||
p1, p1Exp := [32]byte{}, libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000ddeeff")
|
||||
mixedBytes := []interface{}{&p0, &p1}
|
||||
|
||||
buff.Write(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000040"))
|
||||
buff.Write(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000ddeeff"))
|
||||
buff.Write(common.Hex2Bytes("000000000000000000000000000000000000000000000000000000000000000a"))
|
||||
buff.Write(common.Hex2Bytes("0102000000000000000000000000000000000000000000000000000000000000"))
|
||||
buff.Write(libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000040"))
|
||||
buff.Write(libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000ddeeff"))
|
||||
buff.Write(libcommon.Hex2Bytes("000000000000000000000000000000000000000000000000000000000000000a"))
|
||||
buff.Write(libcommon.Hex2Bytes("0102000000000000000000000000000000000000000000000000000000000000"))
|
||||
|
||||
err = abi.UnpackIntoInterface(&mixedBytes, "mixedBytes", buff.Bytes())
|
||||
if err != nil {
|
||||
@ -563,7 +563,7 @@ func TestUnmarshal(t *testing.T) {
|
||||
|
||||
// marshal int
|
||||
var Int *big.Int
|
||||
err = abi.UnpackIntoInterface(&Int, "int", common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000001"))
|
||||
err = abi.UnpackIntoInterface(&Int, "int", libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000001"))
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -574,7 +574,7 @@ func TestUnmarshal(t *testing.T) {
|
||||
|
||||
// marshal bool
|
||||
var Bool bool
|
||||
err = abi.UnpackIntoInterface(&Bool, "bool", common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000001"))
|
||||
err = abi.UnpackIntoInterface(&Bool, "bool", libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000001"))
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@ -585,8 +585,8 @@ func TestUnmarshal(t *testing.T) {
|
||||
|
||||
// marshal dynamic bytes max length 32
|
||||
buff.Reset()
|
||||
buff.Write(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000020"))
|
||||
buff.Write(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000020"))
|
||||
buff.Write(libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000020"))
|
||||
buff.Write(libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000020"))
|
||||
bytesOut := common.RightPadBytes([]byte("hello"), 32)
|
||||
buff.Write(bytesOut)
|
||||
|
||||
@ -602,8 +602,8 @@ func TestUnmarshal(t *testing.T) {
|
||||
|
||||
// marshall dynamic bytes max length 64
|
||||
buff.Reset()
|
||||
buff.Write(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000020"))
|
||||
buff.Write(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000040"))
|
||||
buff.Write(libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000020"))
|
||||
buff.Write(libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000040"))
|
||||
bytesOut = common.RightPadBytes([]byte("hello"), 64)
|
||||
buff.Write(bytesOut)
|
||||
|
||||
@ -618,8 +618,8 @@ func TestUnmarshal(t *testing.T) {
|
||||
|
||||
// marshall dynamic bytes max length 64
|
||||
buff.Reset()
|
||||
buff.Write(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000020"))
|
||||
buff.Write(common.Hex2Bytes("000000000000000000000000000000000000000000000000000000000000003f"))
|
||||
buff.Write(libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000020"))
|
||||
buff.Write(libcommon.Hex2Bytes("000000000000000000000000000000000000000000000000000000000000003f"))
|
||||
bytesOut = common.RightPadBytes([]byte("hello"), 64)
|
||||
buff.Write(bytesOut)
|
||||
|
||||
@ -640,8 +640,8 @@ func TestUnmarshal(t *testing.T) {
|
||||
|
||||
// marshal dynamic bytes length 5
|
||||
buff.Reset()
|
||||
buff.Write(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000020"))
|
||||
buff.Write(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000005"))
|
||||
buff.Write(libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000020"))
|
||||
buff.Write(libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000005"))
|
||||
buff.Write(common.RightPadBytes([]byte("hello"), 32))
|
||||
|
||||
err = abi.UnpackIntoInterface(&Bytes, "bytes", buff.Bytes())
|
||||
@ -670,7 +670,7 @@ func TestUnmarshal(t *testing.T) {
|
||||
|
||||
// marshal error
|
||||
buff.Reset()
|
||||
buff.Write(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000020"))
|
||||
buff.Write(libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000020"))
|
||||
err = abi.UnpackIntoInterface(&Bytes, "bytes", buff.Bytes())
|
||||
if err == nil {
|
||||
t.Error("expected error")
|
||||
@ -682,9 +682,9 @@ func TestUnmarshal(t *testing.T) {
|
||||
}
|
||||
|
||||
buff.Reset()
|
||||
buff.Write(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000001"))
|
||||
buff.Write(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000002"))
|
||||
buff.Write(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000003"))
|
||||
buff.Write(libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000001"))
|
||||
buff.Write(libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000002"))
|
||||
buff.Write(libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000003"))
|
||||
// marshal int array
|
||||
var intArray [3]*big.Int
|
||||
err = abi.UnpackIntoInterface(&intArray, "intArraySingle", buff.Bytes())
|
||||
@ -703,9 +703,9 @@ func TestUnmarshal(t *testing.T) {
|
||||
}
|
||||
// marshal address slice
|
||||
buff.Reset()
|
||||
buff.Write(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000020")) // offset
|
||||
buff.Write(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000001")) // size
|
||||
buff.Write(common.Hex2Bytes("0000000000000000000000000100000000000000000000000000000000000000"))
|
||||
buff.Write(libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000020")) // offset
|
||||
buff.Write(libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000001")) // size
|
||||
buff.Write(libcommon.Hex2Bytes("0000000000000000000000000100000000000000000000000000000000000000"))
|
||||
|
||||
var outAddr []libcommon.Address
|
||||
err = abi.UnpackIntoInterface(&outAddr, "addressSliceSingle", buff.Bytes())
|
||||
@ -723,13 +723,13 @@ func TestUnmarshal(t *testing.T) {
|
||||
|
||||
// marshal multiple address slice
|
||||
buff.Reset()
|
||||
buff.Write(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000040")) // offset
|
||||
buff.Write(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000080")) // offset
|
||||
buff.Write(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000001")) // size
|
||||
buff.Write(common.Hex2Bytes("0000000000000000000000000100000000000000000000000000000000000000"))
|
||||
buff.Write(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000002")) // size
|
||||
buff.Write(common.Hex2Bytes("0000000000000000000000000200000000000000000000000000000000000000"))
|
||||
buff.Write(common.Hex2Bytes("0000000000000000000000000300000000000000000000000000000000000000"))
|
||||
buff.Write(libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000040")) // offset
|
||||
buff.Write(libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000080")) // offset
|
||||
buff.Write(libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000001")) // size
|
||||
buff.Write(libcommon.Hex2Bytes("0000000000000000000000000100000000000000000000000000000000000000"))
|
||||
buff.Write(libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000002")) // size
|
||||
buff.Write(libcommon.Hex2Bytes("0000000000000000000000000200000000000000000000000000000000000000"))
|
||||
buff.Write(libcommon.Hex2Bytes("0000000000000000000000000300000000000000000000000000000000000000"))
|
||||
|
||||
var outAddrStruct struct {
|
||||
A []libcommon.Address
|
||||
@ -761,7 +761,7 @@ func TestUnmarshal(t *testing.T) {
|
||||
|
||||
// marshal invalid address slice
|
||||
buff.Reset()
|
||||
buff.Write(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000100"))
|
||||
buff.Write(libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000100"))
|
||||
|
||||
err = abi.UnpackIntoInterface(&outAddr, "addressSliceSingle", buff.Bytes())
|
||||
if err == nil {
|
||||
@ -777,8 +777,8 @@ func TestUnpackTuple(t *testing.T) {
|
||||
}
|
||||
buff := new(bytes.Buffer)
|
||||
|
||||
buff.Write(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000001")) // ret[a] = 1
|
||||
buff.Write(common.Hex2Bytes("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) // ret[b] = -1
|
||||
buff.Write(libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000001")) // ret[a] = 1
|
||||
buff.Write(libcommon.Hex2Bytes("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) // ret[b] = -1
|
||||
|
||||
// If the result is single tuple, use struct as return value container directly.
|
||||
v := struct {
|
||||
@ -810,21 +810,21 @@ func TestUnpackTuple(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
buff.Reset()
|
||||
buff.Write(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000080")) // s offset
|
||||
buff.Write(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000000")) // t.X = 0
|
||||
buff.Write(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000001")) // t.Y = 1
|
||||
buff.Write(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000001")) // a = 1
|
||||
buff.Write(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000001")) // s.A = 1
|
||||
buff.Write(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000060")) // s.B offset
|
||||
buff.Write(common.Hex2Bytes("00000000000000000000000000000000000000000000000000000000000000c0")) // s.C offset
|
||||
buff.Write(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000002")) // s.B length
|
||||
buff.Write(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000001")) // s.B[0] = 1
|
||||
buff.Write(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000002")) // s.B[0] = 2
|
||||
buff.Write(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000002")) // s.C length
|
||||
buff.Write(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000001")) // s.C[0].X
|
||||
buff.Write(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000002")) // s.C[0].Y
|
||||
buff.Write(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000002")) // s.C[1].X
|
||||
buff.Write(common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000001")) // s.C[1].Y
|
||||
buff.Write(libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000080")) // s offset
|
||||
buff.Write(libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000000")) // t.X = 0
|
||||
buff.Write(libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000001")) // t.Y = 1
|
||||
buff.Write(libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000001")) // a = 1
|
||||
buff.Write(libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000001")) // s.A = 1
|
||||
buff.Write(libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000060")) // s.B offset
|
||||
buff.Write(libcommon.Hex2Bytes("00000000000000000000000000000000000000000000000000000000000000c0")) // s.C offset
|
||||
buff.Write(libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000002")) // s.B length
|
||||
buff.Write(libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000001")) // s.B[0] = 1
|
||||
buff.Write(libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000002")) // s.B[0] = 2
|
||||
buff.Write(libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000002")) // s.C length
|
||||
buff.Write(libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000001")) // s.C[0].X
|
||||
buff.Write(libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000002")) // s.C[0].Y
|
||||
buff.Write(libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000002")) // s.C[1].X
|
||||
buff.Write(libcommon.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000001")) // s.C[1].Y
|
||||
|
||||
type T struct {
|
||||
X *big.Int `abi:"x"`
|
||||
|
@ -43,6 +43,24 @@ type BeaconStateExtension interface {
|
||||
}
|
||||
|
||||
type BeaconStateBasic interface {
|
||||
BeaconStateMinimal
|
||||
BeaconStateExtra
|
||||
BeaconStateMutator
|
||||
BeaconStateSSZ
|
||||
|
||||
Clone() clonable.Clonable
|
||||
DebugPrint(prefix string)
|
||||
}
|
||||
|
||||
type BeaconStateSSZ interface {
|
||||
BlockRoot() ([32]byte, error)
|
||||
EncodeSSZ(buf []byte) ([]byte, error)
|
||||
DecodeSSZ(buf []byte, version int) error
|
||||
EncodingSizeSSZ() (size int)
|
||||
HashSSZ() (out [32]byte, err error)
|
||||
}
|
||||
|
||||
type BeaconStateMutator interface {
|
||||
SetVersion(version clparams.StateVersion)
|
||||
SetSlot(slot uint64)
|
||||
SetFork(fork *cltypes.Fork)
|
||||
@ -56,8 +74,6 @@ type BeaconStateBasic interface {
|
||||
SetActivationEpochForValidatorAtIndex(index int, epoch uint64)
|
||||
SetActivationEligibilityEpochForValidatorAtIndex(index int, epoch uint64)
|
||||
SetEth1Data(eth1Data *cltypes.Eth1Data)
|
||||
AddEth1DataVote(vote *cltypes.Eth1Data)
|
||||
ResetEth1DataVotes()
|
||||
SetEth1DepositIndex(eth1DepositIndex uint64)
|
||||
SetValidatorSlashed(index int, slashed bool) error
|
||||
SetValidatorMinCurrentInclusionDelayAttestation(index int, value *solid.PendingAttestation) error
|
||||
@ -69,13 +85,11 @@ type BeaconStateBasic interface {
|
||||
SetValidatorIsPreviousMatchingTargetAttester(index int, value bool) error
|
||||
SetValidatorIsPreviousMatchingHeadAttester(index int, value bool) error
|
||||
SetValidatorBalance(index int, balance uint64) error
|
||||
AddValidator(validator solid.Validator, balance uint64)
|
||||
SetRandaoMixAt(index int, mix common.Hash)
|
||||
SetSlashingSegmentAt(index int, segment uint64)
|
||||
IncrementSlashingSegmentAt(index int, delta uint64)
|
||||
SetEpochParticipationForValidatorIndex(isCurrentEpoch bool, index int, flags cltypes.ParticipationFlags)
|
||||
SetValidatorAtIndex(index int, validator solid.Validator)
|
||||
ResetEpochParticipation()
|
||||
|
||||
SetJustificationBits(justificationBits cltypes.JustificationBits)
|
||||
SetPreviousJustifiedCheckpoint(previousJustifiedCheckpoint solid.Checkpoint)
|
||||
SetCurrentJustifiedCheckpoint(currentJustifiedCheckpoint solid.Checkpoint)
|
||||
@ -85,22 +99,58 @@ type BeaconStateBasic interface {
|
||||
SetLatestExecutionPayloadHeader(header *cltypes.Eth1Header)
|
||||
SetNextWithdrawalIndex(index uint64)
|
||||
SetNextWithdrawalValidatorIndex(index uint64)
|
||||
ResetHistoricalSummaries()
|
||||
AddHistoricalSummary(summary *cltypes.HistoricalSummary)
|
||||
AddHistoricalRoot(root common.Hash)
|
||||
SetInactivityScores(scores []uint64)
|
||||
AddInactivityScore(score uint64)
|
||||
SetValidatorInactivityScore(index int, score uint64) error
|
||||
SetCurrentEpochParticipationFlags(flags []cltypes.ParticipationFlags)
|
||||
SetPreviousEpochParticipationFlags(flags []cltypes.ParticipationFlags)
|
||||
SetPreviousEpochAttestations(attestations *solid.ListSSZ[*solid.PendingAttestation])
|
||||
|
||||
AddEth1DataVote(vote *cltypes.Eth1Data)
|
||||
AddValidator(validator solid.Validator, balance uint64)
|
||||
AddHistoricalSummary(summary *cltypes.HistoricalSummary)
|
||||
AddHistoricalRoot(root common.Hash)
|
||||
AddInactivityScore(score uint64)
|
||||
AddCurrentEpochParticipationFlags(flags cltypes.ParticipationFlags)
|
||||
AddPreviousEpochParticipationFlags(flags cltypes.ParticipationFlags)
|
||||
AddPreviousEpochParticipationAt(index int, delta byte)
|
||||
AddCurrentEpochAtteastation(attestation *solid.PendingAttestation)
|
||||
AddPreviousEpochAttestation(attestation *solid.PendingAttestation)
|
||||
|
||||
IncrementSlashingSegmentAt(index int, delta uint64)
|
||||
|
||||
AppendValidator(in solid.Validator)
|
||||
|
||||
ResetEth1DataVotes()
|
||||
ResetEpochParticipation()
|
||||
ResetHistoricalSummaries()
|
||||
ResetCurrentEpochAttestations()
|
||||
SetPreviousEpochAttestations(attestations *solid.ListSSZ[*solid.PendingAttestation])
|
||||
ResetPreviousEpochAttestations()
|
||||
}
|
||||
|
||||
type BeaconStateExtra interface {
|
||||
ValidatorLength() int
|
||||
ValidatorBalance(index int) (uint64, error)
|
||||
RandaoMixes() solid.HashVectorSSZ
|
||||
ForEachBalance(fn func(v uint64, idx int, total int) bool)
|
||||
ValidatorExitEpoch(index int) (uint64, error)
|
||||
ValidatorWithdrawableEpoch(index int) (uint64, error)
|
||||
ValidatorEffectiveBalance(index int) (uint64, error)
|
||||
ValidatorMinCurrentInclusionDelayAttestation(index int) (*solid.PendingAttestation, error)
|
||||
ValidatorMinPreviousInclusionDelayAttestation(index int) (*solid.PendingAttestation, error)
|
||||
ValidatorIsCurrentMatchingSourceAttester(idx int) (bool, error)
|
||||
ValidatorIsCurrentMatchingTargetAttester(idx int) (bool, error)
|
||||
ValidatorIsCurrentMatchingHeadAttester(idx int) (bool, error)
|
||||
ValidatorIsPreviousMatchingSourceAttester(idx int) (bool, error)
|
||||
ValidatorIsPreviousMatchingTargetAttester(idx int) (bool, error)
|
||||
ValidatorIsPreviousMatchingHeadAttester(idx int) (bool, error)
|
||||
GetRandaoMixes(epoch uint64) [32]byte
|
||||
GetRandaoMix(index int) [32]byte
|
||||
EpochParticipationForValidatorIndex(isCurrentEpoch bool, index int) cltypes.ParticipationFlags
|
||||
GetBlockRootAtSlot(slot uint64) (common.Hash, error)
|
||||
GetDomain(domainType [4]byte, epoch uint64) ([]byte, error)
|
||||
}
|
||||
|
||||
type BeaconStateMinimal interface {
|
||||
BeaconConfig() *clparams.BeaconChainConfig
|
||||
Version() clparams.StateVersion
|
||||
GenesisTime() uint64
|
||||
@ -114,53 +164,31 @@ type BeaconStateBasic interface {
|
||||
Eth1Data() *cltypes.Eth1Data
|
||||
Eth1DataVotes() *solid.ListSSZ[*cltypes.Eth1Data]
|
||||
Eth1DepositIndex() uint64
|
||||
ValidatorLength() int
|
||||
AppendValidator(in solid.Validator)
|
||||
|
||||
ForEachValidator(fn func(v solid.Validator, idx int, total int) bool)
|
||||
ValidatorForValidatorIndex(index int) (solid.Validator, error)
|
||||
ForEachBalance(fn func(v uint64, idx int, total int) bool)
|
||||
ValidatorBalance(index int) (uint64, error)
|
||||
ValidatorExitEpoch(index int) (uint64, error)
|
||||
ValidatorWithdrawableEpoch(index int) (uint64, error)
|
||||
ValidatorEffectiveBalance(index int) (uint64, error)
|
||||
ValidatorMinCurrentInclusionDelayAttestation(index int) (*solid.PendingAttestation, error)
|
||||
ValidatorMinPreviousInclusionDelayAttestation(index int) (*solid.PendingAttestation, error)
|
||||
ValidatorIsCurrentMatchingSourceAttester(idx int) (bool, error)
|
||||
ValidatorIsCurrentMatchingTargetAttester(idx int) (bool, error)
|
||||
ValidatorIsCurrentMatchingHeadAttester(idx int) (bool, error)
|
||||
ValidatorIsPreviousMatchingSourceAttester(idx int) (bool, error)
|
||||
ValidatorIsPreviousMatchingTargetAttester(idx int) (bool, error)
|
||||
ValidatorIsPreviousMatchingHeadAttester(idx int) (bool, error)
|
||||
RandaoMixes() solid.HashVectorSSZ
|
||||
GetRandaoMixes(epoch uint64) [32]byte
|
||||
GetRandaoMix(index int) [32]byte
|
||||
|
||||
ForEachSlashingSegment(fn func(idx int, v uint64, total int) bool)
|
||||
SlashingSegmentAt(pos int) uint64
|
||||
|
||||
EpochParticipation(currentEpoch bool) *solid.BitList
|
||||
JustificationBits() cltypes.JustificationBits
|
||||
EpochParticipationForValidatorIndex(isCurrentEpoch bool, index int) cltypes.ParticipationFlags
|
||||
|
||||
PreviousJustifiedCheckpoint() solid.Checkpoint
|
||||
CurrentJustifiedCheckpoint() solid.Checkpoint
|
||||
ValidatorInactivityScore(index int) (uint64, error)
|
||||
FinalizedCheckpoint() solid.Checkpoint
|
||||
ValidatorInactivityScore(index int) (uint64, error)
|
||||
CurrentSyncCommittee() *solid.SyncCommittee
|
||||
NextSyncCommittee() *solid.SyncCommittee
|
||||
LatestExecutionPayloadHeader() *cltypes.Eth1Header
|
||||
NextWithdrawalIndex() uint64
|
||||
NextWithdrawalValidatorIndex() uint64
|
||||
// HistoricalSummary has no accessor yet.
|
||||
|
||||
CurrentEpochAttestations() *solid.ListSSZ[*solid.PendingAttestation]
|
||||
CurrentEpochAttestationsLength() int
|
||||
PreviousEpochAttestations() *solid.ListSSZ[*solid.PendingAttestation]
|
||||
PreviousEpochAttestationsLength() int
|
||||
NextWithdrawalValidatorIndex() uint64
|
||||
GetBlockRootAtSlot(slot uint64) (common.Hash, error)
|
||||
GetDomain(domainType [4]byte, epoch uint64) ([]byte, error)
|
||||
DebugPrint(prefix string)
|
||||
BlockRoot() ([32]byte, error)
|
||||
EncodeSSZ(buf []byte) ([]byte, error)
|
||||
DecodeSSZ(buf []byte, version int) error
|
||||
EncodingSizeSSZ() (size int)
|
||||
Clone() clonable.Clonable
|
||||
HashSSZ() (out [32]byte, err error)
|
||||
}
|
||||
|
||||
// TODO figure this out
|
||||
|
@ -29,14 +29,14 @@ func NewDownloader(
|
||||
func (d *Downloader) DownloadEpoch(tx kv.RwTx, ctx context.Context, epoch uint64) error {
|
||||
// convert the epoch to a block
|
||||
startBlock := epoch * d.config.SlotsPerEpoch
|
||||
blocks, err := d.source.GetRange(tx, ctx, startBlock, d.config.SlotsPerEpoch)
|
||||
blocks, err := d.source.GetRange(ctx, tx, startBlock, d.config.SlotsPerEpoch)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// NOTE: the downloader does not perform any real verification on these blocks
|
||||
// validation must be done separately
|
||||
for _, v := range blocks {
|
||||
err := d.beacondDB.WriteBlock(tx, ctx, v.Data, true)
|
||||
err := d.beacondDB.WriteBlock(ctx, tx, v.Data, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package handler
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/ledgerwatch/erigon/cl/sentinel/communication/ssz_snappy"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
@ -11,7 +12,6 @@ import (
|
||||
"github.com/ledgerwatch/erigon/cl/clparams"
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
"github.com/ledgerwatch/erigon/cl/persistence/beacon_indicies"
|
||||
"github.com/ledgerwatch/erigon/cmd/sentinel/sentinel/communication/ssz_snappy"
|
||||
)
|
||||
|
||||
type headerResponse struct {
|
||||
|
@ -1,11 +1,11 @@
|
||||
package cltypes_test
|
||||
|
||||
import (
|
||||
"github.com/ledgerwatch/erigon-lib/common"
|
||||
"testing"
|
||||
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
"github.com/ledgerwatch/erigon/cl/utils"
|
||||
"github.com/ledgerwatch/erigon/common"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
|
@ -6,7 +6,6 @@ import (
|
||||
|
||||
"github.com/ledgerwatch/erigon/cl/merkle_tree"
|
||||
ssz2 "github.com/ledgerwatch/erigon/cl/ssz"
|
||||
"github.com/ledgerwatch/erigon/common"
|
||||
)
|
||||
|
||||
type Eth1Data struct {
|
||||
@ -36,7 +35,7 @@ func (e *Eth1Data) DecodeSSZ(buf []byte, _ int) error {
|
||||
|
||||
// EncodingSizeSSZ returns the ssz encoded size in bytes for the Eth1Data object
|
||||
func (e *Eth1Data) EncodingSizeSSZ() int {
|
||||
return common.BlockNumberLength + length.Hash*2
|
||||
return 8 + length.Hash*2
|
||||
}
|
||||
|
||||
// HashSSZ ssz hashes the Eth1Data object
|
||||
|
@ -8,7 +8,6 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
"github.com/ledgerwatch/erigon/common"
|
||||
)
|
||||
|
||||
var testEth1Data = &cltypes.Eth1Data{
|
||||
@ -17,8 +16,8 @@ var testEth1Data = &cltypes.Eth1Data{
|
||||
DepositCount: 69,
|
||||
}
|
||||
|
||||
var expectedTestEth1DataMarshalled = common.Hex2Bytes("000000000000000000000000000000000000000000000000000000000000000245000000000000000000000000000000000000000000000000000000000000000000000000000003")
|
||||
var expectedTestEth1DataRoot = common.Hex2Bytes("adbafa10f1d6046b59cb720371c5e70ce2c6c3067b0e87985f5cd0899a515886")
|
||||
var expectedTestEth1DataMarshalled = libcommon.Hex2Bytes("000000000000000000000000000000000000000000000000000000000000000245000000000000000000000000000000000000000000000000000000000000000000000000000003")
|
||||
var expectedTestEth1DataRoot = libcommon.Hex2Bytes("adbafa10f1d6046b59cb720371c5e70ce2c6c3067b0e87985f5cd0899a515886")
|
||||
|
||||
func TestEth1DataMarshalUnmarmashal(t *testing.T) {
|
||||
marshalled, _ := testEth1Data.EncodeSSZ(nil)
|
||||
|
@ -1,11 +1,11 @@
|
||||
package cltypes_test
|
||||
|
||||
import (
|
||||
"github.com/ledgerwatch/erigon-lib/common"
|
||||
"testing"
|
||||
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
"github.com/ledgerwatch/erigon/cl/utils"
|
||||
"github.com/ledgerwatch/erigon/common"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
|
@ -5,7 +5,6 @@ import (
|
||||
"github.com/ledgerwatch/erigon-lib/types/ssz"
|
||||
|
||||
ssz2 "github.com/ledgerwatch/erigon/cl/ssz"
|
||||
"github.com/ledgerwatch/erigon/common"
|
||||
)
|
||||
|
||||
type Metadata struct {
|
||||
@ -22,7 +21,7 @@ func (m *Metadata) EncodeSSZ(buf []byte) ([]byte, error) {
|
||||
}
|
||||
|
||||
func (m *Metadata) EncodingSizeSSZ() (ret int) {
|
||||
ret = common.BlockNumberLength * 2
|
||||
ret = 8 * 2
|
||||
if m.Syncnets != nil {
|
||||
ret += 8
|
||||
}
|
||||
@ -50,7 +49,7 @@ func (p *Ping) EncodeSSZ(buf []byte) ([]byte, error) {
|
||||
}
|
||||
|
||||
func (p *Ping) EncodingSizeSSZ() int {
|
||||
return common.BlockNumberLength
|
||||
return 8
|
||||
}
|
||||
|
||||
func (p *Ping) DecodeSSZ(buf []byte, _ int) error {
|
||||
@ -76,7 +75,7 @@ func (b *BeaconBlocksByRangeRequest) DecodeSSZ(buf []byte, v int) error {
|
||||
}
|
||||
|
||||
func (b *BeaconBlocksByRangeRequest) EncodingSizeSSZ() int {
|
||||
return 3 * common.BlockNumberLength
|
||||
return 3 * 8
|
||||
}
|
||||
|
||||
func (*BeaconBlocksByRangeRequest) Clone() clonable.Clonable {
|
||||
|
@ -9,7 +9,6 @@ import (
|
||||
"github.com/ledgerwatch/erigon-lib/types/clonable"
|
||||
"github.com/ledgerwatch/erigon-lib/types/ssz"
|
||||
"github.com/ledgerwatch/erigon/cl/merkle_tree"
|
||||
"github.com/ledgerwatch/erigon/common"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -121,7 +120,7 @@ func (a *Attestation) DecodeSSZ(buf []byte, _ int) error {
|
||||
return ssz.ErrLowBufferSize
|
||||
}
|
||||
copy(a.staticBuffer[:], buf)
|
||||
a.aggregationBitsBuffer = common.CopyBytes(buf[aggregationBitsOffset:])
|
||||
a.aggregationBitsBuffer = libcommon.CopyBytes(buf[aggregationBitsOffset:])
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,12 @@
|
||||
package solid
|
||||
|
||||
import (
|
||||
"github.com/ledgerwatch/erigon-lib/common"
|
||||
"math/bits"
|
||||
|
||||
"github.com/ledgerwatch/erigon-lib/types/clonable"
|
||||
"github.com/ledgerwatch/erigon/cl/merkle_tree"
|
||||
"github.com/ledgerwatch/erigon/cl/utils"
|
||||
"github.com/ledgerwatch/erigon/common"
|
||||
)
|
||||
|
||||
// BitList is like a dynamic binary string. It's like a flipbook of 1s and 0s!
|
||||
|
@ -8,13 +8,12 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes/solid"
|
||||
"github.com/ledgerwatch/erigon/common"
|
||||
)
|
||||
|
||||
var testCheckpoint = solid.NewCheckpointFromParameters(libcommon.HexToHash("0x3"), 69)
|
||||
|
||||
var expectedTestCheckpointMarshalled = common.Hex2Bytes("45000000000000000000000000000000000000000000000000000000000000000000000000000003")
|
||||
var expectedTestCheckpointRoot = common.Hex2Bytes("be8567f9fdae831b10720823dbcf0e3680e61d6a2a27d85ca00f6c15a7bbb1ea")
|
||||
var expectedTestCheckpointMarshalled = libcommon.Hex2Bytes("45000000000000000000000000000000000000000000000000000000000000000000000000000003")
|
||||
var expectedTestCheckpointRoot = libcommon.Hex2Bytes("be8567f9fdae831b10720823dbcf0e3680e61d6a2a27d85ca00f6c15a7bbb1ea")
|
||||
|
||||
func TestCheckpointMarshalUnmarmashal(t *testing.T) {
|
||||
marshalled, err := testCheckpoint.EncodeSSZ(nil)
|
||||
|
@ -2,11 +2,11 @@ package solid
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"github.com/ledgerwatch/erigon-lib/common"
|
||||
|
||||
"github.com/ledgerwatch/erigon-lib/types/clonable"
|
||||
"github.com/ledgerwatch/erigon-lib/types/ssz"
|
||||
"github.com/ledgerwatch/erigon/cl/merkle_tree"
|
||||
"github.com/ledgerwatch/erigon/common"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -3,9 +3,9 @@ package freezer
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"github.com/ledgerwatch/erigon/cl/sentinel/communication/ssz_snappy"
|
||||
|
||||
"github.com/ledgerwatch/erigon-lib/types/ssz"
|
||||
"github.com/ledgerwatch/erigon/cmd/sentinel/sentinel/communication/ssz_snappy"
|
||||
)
|
||||
|
||||
type marshalerHashable interface {
|
||||
|
@ -6,6 +6,8 @@ import (
|
||||
"io"
|
||||
"path"
|
||||
|
||||
"github.com/ledgerwatch/erigon/cl/sentinel/communication/ssz_snappy"
|
||||
|
||||
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
||||
"github.com/ledgerwatch/erigon-lib/kv"
|
||||
"github.com/ledgerwatch/erigon/cl/clparams"
|
||||
@ -13,7 +15,6 @@ import (
|
||||
"github.com/ledgerwatch/erigon/cl/persistence/beacon_indicies"
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/execution_client"
|
||||
"github.com/ledgerwatch/erigon/cl/sentinel/peers"
|
||||
"github.com/ledgerwatch/erigon/cmd/sentinel/sentinel/communication/ssz_snappy"
|
||||
"github.com/spf13/afero"
|
||||
)
|
||||
|
||||
@ -32,7 +33,7 @@ func NewBeaconChainDatabaseFilesystem(rawDB RawBeaconBlockChain, executionEngine
|
||||
}
|
||||
}
|
||||
|
||||
func (b beaconChainDatabaseFilesystem) GetRange(tx kv.Tx, ctx context.Context, from uint64, count uint64) ([]*peers.PeeredObject[*cltypes.SignedBeaconBlock], error) {
|
||||
func (b beaconChainDatabaseFilesystem) GetRange(ctx context.Context, tx kv.Tx, from uint64, count uint64) ([]*peers.PeeredObject[*cltypes.SignedBeaconBlock], error) {
|
||||
// Retrieve block roots for each ranged slot
|
||||
beaconBlockRooots, slots, err := beacon_indicies.ReadBeaconBlockRootsInSlotRange(ctx, tx, from, count)
|
||||
if err != nil {
|
||||
@ -65,7 +66,7 @@ func (b beaconChainDatabaseFilesystem) GetRange(tx kv.Tx, ctx context.Context, f
|
||||
|
||||
}
|
||||
|
||||
func (b beaconChainDatabaseFilesystem) PurgeRange(tx kv.RwTx, ctx context.Context, from uint64, count uint64) error {
|
||||
func (b beaconChainDatabaseFilesystem) PurgeRange(ctx context.Context, tx kv.RwTx, from uint64, count uint64) error {
|
||||
if err := beacon_indicies.RangeBlockRoots(ctx, tx, from, from+count, func(slot uint64, beaconBlockRoot libcommon.Hash) bool {
|
||||
b.rawDB.DeleteBlock(ctx, slot, beaconBlockRoot)
|
||||
return true
|
||||
@ -76,7 +77,7 @@ func (b beaconChainDatabaseFilesystem) PurgeRange(tx kv.RwTx, ctx context.Contex
|
||||
return beacon_indicies.PruneBlockRoots(ctx, tx, from, from+count)
|
||||
}
|
||||
|
||||
func (b beaconChainDatabaseFilesystem) WriteBlock(tx kv.RwTx, ctx context.Context, block *cltypes.SignedBeaconBlock, canonical bool) error {
|
||||
func (b beaconChainDatabaseFilesystem) WriteBlock(ctx context.Context, tx kv.RwTx, block *cltypes.SignedBeaconBlock, canonical bool) error {
|
||||
blockRoot, err := block.Block.HashSSZ()
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -116,9 +116,9 @@ func TestBlockSaverStoreLoadPurgeFull(t *testing.T) {
|
||||
|
||||
ctx := context.Background()
|
||||
block := getTestBlock()
|
||||
require.NoError(t, store.WriteBlock(tx, ctx, block, true))
|
||||
require.NoError(t, store.WriteBlock(ctx, tx, block, true))
|
||||
|
||||
blks, err := store.GetRange(tx, context.Background(), block.Block.Slot, 1)
|
||||
blks, err := store.GetRange(context.Background(), tx, block.Block.Slot, 1)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, len(blks), 1)
|
||||
|
||||
@ -130,9 +130,9 @@ func TestBlockSaverStoreLoadPurgeFull(t *testing.T) {
|
||||
|
||||
require.Equal(t, expectedRoot, haveRoot)
|
||||
|
||||
require.NoError(t, store.PurgeRange(tx, ctx, 0, 99999999999)) // THE PUURGE
|
||||
require.NoError(t, store.PurgeRange(ctx, tx, 0, 99999999999)) // THE PUURGE
|
||||
|
||||
newBlks, err := store.GetRange(tx, context.Background(), block.Block.Slot, 1)
|
||||
newBlks, err := store.GetRange(context.Background(), tx, block.Block.Slot, 1)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, len(newBlks), 0)
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ func NewBeaconRpcSource(rpc *rpc.BeaconRpcP2P) *BeaconRpcSource {
|
||||
}
|
||||
}
|
||||
|
||||
func (b *BeaconRpcSource) GetRange(_ kv.Tx, ctx context.Context, from uint64, count uint64) ([]*peers.PeeredObject[*cltypes.SignedBeaconBlock], error) {
|
||||
func (b *BeaconRpcSource) GetRange(ctx context.Context, _ kv.Tx, from uint64, count uint64) ([]*peers.PeeredObject[*cltypes.SignedBeaconBlock], error) {
|
||||
if count == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
@ -46,7 +46,7 @@ func (b *BeaconRpcSource) GetRange(_ kv.Tx, ctx context.Context, from uint64, co
|
||||
}
|
||||
|
||||
// a noop for rpc source since we always return new data
|
||||
func (b *BeaconRpcSource) PurgeRange(_ kv.RwTx, ctx context.Context, from uint64, count uint64) error {
|
||||
func (b *BeaconRpcSource) PurgeRange(ctx context.Context, _ kv.RwTx, from uint64, count uint64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -93,7 +93,7 @@ func (b *GossipSource) grabOrCreate(ctx context.Context, id uint64) chan *peers.
|
||||
}
|
||||
return ch
|
||||
}
|
||||
func (b *GossipSource) GetRange(_ kv.Tx, ctx context.Context, from uint64, count uint64) ([]*peers.PeeredObject[*cltypes.SignedBeaconBlock], error) {
|
||||
func (b *GossipSource) GetRange(ctx context.Context, _ kv.Tx, from uint64, count uint64) ([]*peers.PeeredObject[*cltypes.SignedBeaconBlock], error) {
|
||||
out := make([]*peers.PeeredObject[*cltypes.SignedBeaconBlock], 0, count)
|
||||
for i := from; i < from+count; i++ {
|
||||
ch := b.grabOrCreate(ctx, i)
|
||||
@ -107,7 +107,7 @@ func (b *GossipSource) GetRange(_ kv.Tx, ctx context.Context, from uint64, count
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (b *GossipSource) PurgeRange(_ kv.RwTx, ctx context.Context, from uint64, count uint64) error {
|
||||
func (b *GossipSource) PurgeRange(ctx context.Context, _ kv.RwTx, from uint64, count uint64) error {
|
||||
b.mu.Lock()
|
||||
defer b.mu.Unlock()
|
||||
initSize := count
|
||||
|
@ -11,12 +11,12 @@ import (
|
||||
)
|
||||
|
||||
type BlockSource interface {
|
||||
GetRange(tx kv.Tx, ctx context.Context, from uint64, count uint64) ([]*peers.PeeredObject[*cltypes.SignedBeaconBlock], error)
|
||||
PurgeRange(tx kv.RwTx, ctx context.Context, from uint64, count uint64) error
|
||||
GetRange(ctx context.Context, tx kv.Tx, from uint64, count uint64) ([]*peers.PeeredObject[*cltypes.SignedBeaconBlock], error)
|
||||
PurgeRange(ctx context.Context, tx kv.RwTx, from uint64, count uint64) error
|
||||
}
|
||||
|
||||
type BeaconChainWriter interface {
|
||||
WriteBlock(tx kv.RwTx, ctx context.Context, block *cltypes.SignedBeaconBlock, canonical bool) error
|
||||
WriteBlock(ctx context.Context, tx kv.RwTx, block *cltypes.SignedBeaconBlock, canonical bool) error
|
||||
}
|
||||
|
||||
type RawBeaconBlockChain interface {
|
||||
|
61
cl/phase1/core/rawdb/config.go
Normal file
61
cl/phase1/core/rawdb/config.go
Normal file
@ -0,0 +1,61 @@
|
||||
package rawdb
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"math"
|
||||
|
||||
"github.com/ledgerwatch/erigon-lib/kv"
|
||||
)
|
||||
|
||||
type BeaconDataConfig struct {
|
||||
BackFillingAmount uint64 `json:"backFillingAmount"` // it is string to handle all/minimal.
|
||||
SlotPerRestorePoint uint64 `json:"sprp"` // TODO
|
||||
}
|
||||
|
||||
var beaconDataKey = []byte("beaconData")
|
||||
|
||||
// Configurations for beacon database config
|
||||
var BeaconDataConfigurations map[string]*BeaconDataConfig = map[string]*BeaconDataConfig{
|
||||
"full": {
|
||||
BackFillingAmount: math.MaxUint64,
|
||||
SlotPerRestorePoint: 0,
|
||||
},
|
||||
"minimal": {
|
||||
BackFillingAmount: 500_000,
|
||||
SlotPerRestorePoint: 0,
|
||||
},
|
||||
"light": {
|
||||
BackFillingAmount: 0,
|
||||
SlotPerRestorePoint: 0,
|
||||
},
|
||||
}
|
||||
|
||||
func WriteBeaconDataConfig(tx kv.Putter, cfg *BeaconDataConfig) error {
|
||||
var (
|
||||
data []byte
|
||||
err error
|
||||
)
|
||||
if data, err = json.Marshal(cfg); err != nil {
|
||||
return err
|
||||
}
|
||||
return tx.Put(kv.DatabaseInfo, beaconDataKey, data)
|
||||
}
|
||||
|
||||
func ReadBeaconDataConfig(tx kv.Getter) (*BeaconDataConfig, error) {
|
||||
var (
|
||||
data []byte
|
||||
err error
|
||||
cfg = &BeaconDataConfig{}
|
||||
)
|
||||
if data, err = tx.GetOne(kv.DatabaseInfo, beaconDataKey); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(data) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
if err = json.Unmarshal(data, &cfg); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return cfg, nil
|
||||
}
|
@ -4,7 +4,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
lru "github.com/hashicorp/golang-lru/v2"
|
||||
"github.com/ledgerwatch/erigon/metrics"
|
||||
"github.com/ledgerwatch/erigon-lib/metrics"
|
||||
)
|
||||
|
||||
// Cache is a wrapper around hashicorp lru but with metric for Get
|
||||
|
@ -2,12 +2,12 @@ package shuffling_test
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"github.com/ledgerwatch/erigon-lib/common/eth2shuffle"
|
||||
"testing"
|
||||
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/core/state"
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/core/state/raw"
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/core/state/shuffling"
|
||||
"github.com/ledgerwatch/erigon/common/eth2shuffle"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/ledgerwatch/erigon/cl/clparams"
|
||||
|
@ -3,11 +3,11 @@ package shuffling
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"github.com/ledgerwatch/erigon-lib/common/eth2shuffle"
|
||||
|
||||
"github.com/ledgerwatch/erigon-lib/common"
|
||||
"github.com/ledgerwatch/erigon/cl/clparams"
|
||||
"github.com/ledgerwatch/erigon/cl/utils"
|
||||
"github.com/ledgerwatch/erigon/common/eth2shuffle"
|
||||
)
|
||||
|
||||
func ComputeShuffledIndex(conf *clparams.BeaconChainConfig, ind, ind_count uint64, seed [32]byte, preInputs [][32]byte, hashFunc utils.HashFunc) (uint64, error) {
|
||||
|
@ -1,8 +1,8 @@
|
||||
package state
|
||||
|
||||
import (
|
||||
"github.com/ledgerwatch/erigon-lib/metrics"
|
||||
"github.com/ledgerwatch/erigon-lib/types/clonable"
|
||||
"github.com/ledgerwatch/erigon/metrics"
|
||||
)
|
||||
|
||||
func (b *CachingBeaconState) EncodeSSZ(buf []byte) ([]byte, error) {
|
||||
|
@ -3,6 +3,7 @@ package execution_client
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/ledgerwatch/erigon-lib/common/hexutil"
|
||||
"math/big"
|
||||
"net/http"
|
||||
"strings"
|
||||
@ -12,7 +13,6 @@ import (
|
||||
"github.com/ledgerwatch/erigon/cl/clparams"
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/execution_client/rpc_helper"
|
||||
"github.com/ledgerwatch/erigon/common/hexutil"
|
||||
"github.com/ledgerwatch/erigon/core/types"
|
||||
"github.com/ledgerwatch/erigon/rpc"
|
||||
"github.com/ledgerwatch/erigon/turbo/engineapi/engine_types"
|
||||
|
@ -8,22 +8,22 @@ func main() {}
|
||||
// "fmt"
|
||||
// "os"
|
||||
|
||||
// "github.com/ledgerwatch/erigon/cl/phase1/core"
|
||||
// "github.com/ledgerwatch/erigon/cl/phase1/core/state"
|
||||
// "github.com/ledgerwatch/erigon/cl/phase1/execution_client"
|
||||
// "github.com/ledgerwatch/erigon/cl/phase1/forkchoice"
|
||||
// network2 "github.com/ledgerwatch/erigon/cl/phase1/network"
|
||||
// stages2 "github.com/ledgerwatch/erigon/cl/phase1/stages"
|
||||
// rawdb2 "github.com/ledgerwatch/erigon/cl/phase4/rawdb"
|
||||
// "github.com/ledgerwatch/erigon-lib/cl/phase1/core"
|
||||
// "github.com/ledgerwatch/erigon-lib/cl/phase1/core/state"
|
||||
// "github.com/ledgerwatch/erigon-lib/cl/phase1/execution_client"
|
||||
// "github.com/ledgerwatch/erigon-lib/cl/phase1/forkchoice"
|
||||
// network2 "github.com/ledgerwatch/erigon-lib/cl/phase1/network"
|
||||
// stages2 "github.com/ledgerwatch/erigon-lib/cl/phase1/stages"
|
||||
// rawdb2 "github.com/ledgerwatch/erigon-lib/cl/phase4/rawdb"
|
||||
|
||||
// sentinelrpc "github.com/ledgerwatch/erigon-lib/gointerfaces/sentinel"
|
||||
// "github.com/ledgerwatch/erigon-lib/kv"
|
||||
// "github.com/ledgerwatch/erigon-lib/kv/mdbx"
|
||||
// "github.com/ledgerwatch/erigon/cl/clparams"
|
||||
// "github.com/ledgerwatch/erigon/cl/clparams/initial_state"
|
||||
// "github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
// "github.com/ledgerwatch/erigon/cl/fork"
|
||||
// "github.com/ledgerwatch/erigon/cl/rpc"
|
||||
// "github.com/ledgerwatch/erigon-lib/cl/clparams"
|
||||
// "github.com/ledgerwatch/erigon-lib/cl/clparams/initial_state"
|
||||
// "github.com/ledgerwatch/erigon-lib/cl/cltypes"
|
||||
// "github.com/ledgerwatch/erigon-lib/cl/fork"
|
||||
// "github.com/ledgerwatch/erigon-lib/cl/rpc"
|
||||
// lcCli "github.com/ledgerwatch/erigon/cmd/sentinel/cli"
|
||||
|
||||
// "github.com/ledgerwatch/erigon/cmd/sentinel/cli/flags"
|
||||
|
@ -3,6 +3,7 @@ package network
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/ledgerwatch/erigon-lib/common"
|
||||
"sync"
|
||||
|
||||
"github.com/ledgerwatch/erigon/cl/freezer"
|
||||
@ -14,7 +15,6 @@ import (
|
||||
"github.com/ledgerwatch/erigon/cl/clparams"
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
"github.com/ledgerwatch/erigon/cl/utils"
|
||||
"github.com/ledgerwatch/erigon/common"
|
||||
"github.com/ledgerwatch/log/v3"
|
||||
)
|
||||
|
||||
|
@ -39,6 +39,8 @@ type Cfg struct {
|
||||
indiciesDB kv.RwDB
|
||||
tmpdir string
|
||||
dbConfig db_config.DatabaseConfiguration
|
||||
|
||||
hasDownloaded bool
|
||||
}
|
||||
|
||||
type Args struct {
|
||||
@ -47,7 +49,7 @@ type Args struct {
|
||||
targetEpoch, seenEpoch uint64
|
||||
targetSlot, seenSlot uint64
|
||||
|
||||
downloadedHistory bool
|
||||
hasDownloaded bool
|
||||
}
|
||||
|
||||
func ClStagesCfg(
|
||||
@ -99,7 +101,7 @@ func MetaCatchingUp(args Args) StageName {
|
||||
if args.peers < minPeersForDownload {
|
||||
return WaitForPeers
|
||||
}
|
||||
if !args.downloadedHistory {
|
||||
if !args.hasDownloaded {
|
||||
return DownloadHistoricalBlocks
|
||||
}
|
||||
if args.seenEpoch < args.targetEpoch {
|
||||
@ -171,14 +173,13 @@ func ConsensusClStages(ctx context.Context,
|
||||
return err
|
||||
}
|
||||
// Write block to database optimistically if we are very behind.
|
||||
return cfg.beaconDB.WriteBlock(tx, ctx, block.Data, false)
|
||||
return cfg.beaconDB.WriteBlock(ctx, tx, block.Data, false)
|
||||
}
|
||||
|
||||
// TODO: this is an ugly hack, but it works! Basically, we want shared state in the clstages.
|
||||
// Probably the correct long term solution is to create a third generic parameter that defines shared state
|
||||
// but for now, all it would have are the two gossip sources and the forkChoicesSinceReorg, so i don't think its worth it (yet).
|
||||
shouldForkChoiceSinceReorg := false
|
||||
downloaded := false
|
||||
|
||||
// clstages run in a single thread - so we don't need to worry about any synchronization.
|
||||
return &clstages.StageGraph[*Cfg, Args]{
|
||||
@ -190,7 +191,7 @@ func ConsensusClStages(ctx context.Context,
|
||||
log.Error("failed to get sentinel peer count", "err", err)
|
||||
args.peers = 0
|
||||
}
|
||||
args.downloadedHistory = downloaded
|
||||
args.hasDownloaded = cfg.hasDownloaded
|
||||
args.seenSlot = cfg.forkChoice.HighestSeen()
|
||||
args.seenEpoch = args.seenSlot / cfg.beaconCfg.SlotsPerEpoch
|
||||
args.targetSlot = utils.GetCurrentSlot(cfg.genesisCfg.GenesisTime, cfg.beaconCfg.SecondsPerSlot)
|
||||
@ -241,7 +242,7 @@ func ConsensusClStages(ctx context.Context,
|
||||
return CatchUpBlocks
|
||||
},
|
||||
ActionFunc: func(ctx context.Context, logger log.Logger, cfg *Cfg, args Args) error {
|
||||
downloaded = true
|
||||
cfg.hasDownloaded = true
|
||||
startingRoot, err := cfg.state.BlockRoot()
|
||||
if err != nil {
|
||||
return err
|
||||
@ -250,7 +251,7 @@ func ConsensusClStages(ctx context.Context,
|
||||
downloader := network2.NewBackwardBeaconDownloader(ctx, cfg.rpc)
|
||||
|
||||
if err := SpawnStageHistoryDownload(StageHistoryReconstruction(downloader, cfg.beaconDB, cfg.indiciesDB, cfg.executionClient, cfg.genesisCfg, cfg.beaconCfg, cfg.dbConfig, startingRoot, startingSlot, cfg.tmpdir, logger), ctx, logger); err != nil {
|
||||
downloaded = false
|
||||
cfg.hasDownloaded = false
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
@ -277,7 +278,7 @@ func ConsensusClStages(ctx context.Context,
|
||||
MainLoop:
|
||||
for currentEpoch <= args.targetEpoch+1 {
|
||||
startBlock := currentEpoch * cfg.beaconCfg.SlotsPerEpoch
|
||||
blocks, err := rpcSource.GetRange(tx, ctx, startBlock, cfg.beaconCfg.SlotsPerEpoch)
|
||||
blocks, err := rpcSource.GetRange(ctx, tx, startBlock, cfg.beaconCfg.SlotsPerEpoch)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -338,7 +339,12 @@ func ConsensusClStages(ctx context.Context,
|
||||
)
|
||||
respCh := make(chan []*peers.PeeredObject[*cltypes.SignedBeaconBlock])
|
||||
errCh := make(chan error)
|
||||
sources := []persistence.BlockSource{gossipSource, rpcSource}
|
||||
sources := []persistence.BlockSource{gossipSource}
|
||||
|
||||
// if we are more than one block behind, we request the rpc source as well
|
||||
if totalRequest > 2 {
|
||||
sources = append(sources, rpcSource)
|
||||
}
|
||||
// the timeout is equal to the amount of blocks to fetch multiplied by the seconds per slot
|
||||
ctx, cn := context.WithTimeout(ctx, time.Duration(cfg.beaconCfg.SecondsPerSlot*totalRequest)*time.Second)
|
||||
defer cn()
|
||||
@ -352,7 +358,7 @@ func ConsensusClStages(ctx context.Context,
|
||||
for _, v := range sources {
|
||||
sourceFunc := v.GetRange
|
||||
go func() {
|
||||
blocks, err := sourceFunc(tx, ctx, args.seenSlot+1, totalRequest)
|
||||
blocks, err := sourceFunc(ctx, tx, args.seenSlot+1, totalRequest)
|
||||
if err != nil {
|
||||
errCh <- err
|
||||
return
|
||||
@ -491,7 +497,7 @@ func ConsensusClStages(ctx context.Context,
|
||||
}
|
||||
defer tx.Rollback()
|
||||
// try to get the current block
|
||||
blocks, err := gossipSource.GetRange(tx, ctx, args.seenSlot, 1)
|
||||
blocks, err := gossipSource.GetRange(ctx, tx, args.seenSlot, 1)
|
||||
if err != nil {
|
||||
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
|
||||
return nil
|
||||
@ -527,11 +533,11 @@ func ConsensusClStages(ctx context.Context,
|
||||
}
|
||||
defer tx.Rollback()
|
||||
// clean up some old ranges
|
||||
err = gossipSource.PurgeRange(tx, ctx, 1, args.seenSlot-cfg.beaconCfg.SlotsPerEpoch*16)
|
||||
err = gossipSource.PurgeRange(ctx, tx, 1, args.seenSlot-cfg.beaconCfg.SlotsPerEpoch*16)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = cfg.beaconDB.PurgeRange(tx, ctx, 1, cfg.forkChoice.HighestSeen()-cfg.dbConfig.PruneDepth)
|
||||
err = cfg.beaconDB.PurgeRange(ctx, tx, 1, cfg.forkChoice.HighestSeen()-cfg.dbConfig.PruneDepth)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -6,6 +6,8 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/ledgerwatch/erigon-lib/kv/dbutils"
|
||||
|
||||
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
||||
"github.com/ledgerwatch/erigon-lib/etl"
|
||||
"github.com/ledgerwatch/erigon-lib/kv"
|
||||
@ -15,7 +17,6 @@ import (
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/execution_client"
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/network"
|
||||
"github.com/ledgerwatch/erigon/cl/utils"
|
||||
"github.com/ledgerwatch/erigon/common/dbutils"
|
||||
"github.com/ledgerwatch/erigon/core/types"
|
||||
|
||||
"github.com/ledgerwatch/erigon/cl/clparams"
|
||||
@ -95,7 +96,7 @@ func SpawnStageHistoryDownload(cfg StageHistoryReconstructionCfg, ctx context.Co
|
||||
|
||||
slot := blk.Block.Slot
|
||||
if destinationSlot <= blk.Block.Slot {
|
||||
if err := cfg.db.WriteBlock(tx, ctx, blk, true); err != nil {
|
||||
if err := cfg.db.WriteBlock(ctx, tx, blk, true); err != nil {
|
||||
return false, err
|
||||
}
|
||||
}
|
||||
@ -120,7 +121,6 @@ func SpawnStageHistoryDownload(cfg StageHistoryReconstructionCfg, ctx context.Co
|
||||
}
|
||||
foundLatestEth1ValidBlock = len(bodyChainHeader) > 0 || cfg.engine.FrozenBlocks() > payload.BlockNumber
|
||||
}
|
||||
|
||||
return slot <= destinationSlot && foundLatestEth1ValidBlock, nil
|
||||
})
|
||||
prevProgress := cfg.downloader.Progress()
|
||||
|
@ -2,10 +2,10 @@ package pool
|
||||
|
||||
import (
|
||||
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
||||
"github.com/ledgerwatch/erigon-lib/crypto/blake2b"
|
||||
"github.com/ledgerwatch/erigon/cl/clparams"
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes/solid"
|
||||
"github.com/ledgerwatch/erigon/crypto/blake2b"
|
||||
)
|
||||
|
||||
// DoubleSignatureKey uses blake2b algorithm to merge two signatures together. blake2 is faster than sha3.
|
||||
|
3
cl/readme.md
Normal file
3
cl/readme.md
Normal file
@ -0,0 +1,3 @@
|
||||
# cl
|
||||
|
||||
all code under this directory and subdirectories falls under apache 2.0 license, seen in ./LICENSE
|
@ -8,6 +8,9 @@ import (
|
||||
"io"
|
||||
"time"
|
||||
|
||||
"github.com/ledgerwatch/erigon/cl/sentinel/communication"
|
||||
"github.com/ledgerwatch/erigon/cl/sentinel/communication/ssz_snappy"
|
||||
|
||||
"github.com/c2h5oh/datasize"
|
||||
"github.com/golang/snappy"
|
||||
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
||||
@ -21,9 +24,6 @@ import (
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes/solid"
|
||||
"github.com/ledgerwatch/erigon/cl/fork"
|
||||
"github.com/ledgerwatch/erigon/cl/utils"
|
||||
"github.com/ledgerwatch/erigon/cmd/sentinel/sentinel/communication"
|
||||
"github.com/ledgerwatch/erigon/cmd/sentinel/sentinel/communication/ssz_snappy"
|
||||
"github.com/ledgerwatch/erigon/common"
|
||||
)
|
||||
|
||||
const maxMessageLength = 18 * datasize.MB
|
||||
@ -67,7 +67,7 @@ func (b *BeaconRpcP2P) sendBlocksRequest(ctx context.Context, topic string, reqD
|
||||
if message.Error {
|
||||
rd := snappy.NewReader(bytes.NewBuffer(message.Data))
|
||||
errBytes, _ := io.ReadAll(rd)
|
||||
log.Debug("received range req error", "err", string(errBytes))
|
||||
log.Debug("received range req error", "err", string(errBytes), "raw", string(message.Data))
|
||||
return nil, message.Peer.Pid, nil
|
||||
}
|
||||
|
||||
@ -137,7 +137,7 @@ func (b *BeaconRpcP2P) SendBeaconBlocksByRangeReq(ctx context.Context, start, co
|
||||
return nil, "", err
|
||||
}
|
||||
|
||||
data := common.CopyBytes(buffer.Bytes())
|
||||
data := libcommon.CopyBytes(buffer.Bytes())
|
||||
return b.sendBlocksRequest(ctx, communication.BeaconBlocksByRangeProtocolV2, data, count)
|
||||
}
|
||||
|
||||
@ -151,7 +151,7 @@ func (b *BeaconRpcP2P) SendBeaconBlocksByRootReq(ctx context.Context, roots [][3
|
||||
if err := ssz_snappy.EncodeAndWrite(&buffer, req); err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
data := common.CopyBytes(buffer.Bytes())
|
||||
data := libcommon.CopyBytes(buffer.Bytes())
|
||||
return b.sendBlocksRequest(ctx, communication.BeaconBlocksByRootProtocolV2, data, uint64(len(roots)))
|
||||
}
|
||||
|
||||
|
@ -1,16 +1,3 @@
|
||||
/*
|
||||
Copyright 2022 Erigon-Lightclient contributors
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package sentinel
|
||||
|
||||
import (
|
||||
@ -20,40 +7,37 @@ import (
|
||||
|
||||
"github.com/ledgerwatch/erigon/cl/clparams"
|
||||
"github.com/ledgerwatch/erigon/cl/fork"
|
||||
"github.com/ledgerwatch/erigon/cmd/sentinel/sentinel/peers"
|
||||
"github.com/ledgerwatch/erigon/p2p/enode"
|
||||
"github.com/ledgerwatch/erigon/p2p/enr"
|
||||
"github.com/ledgerwatch/log/v3"
|
||||
"github.com/libp2p/go-libp2p/core/network"
|
||||
"github.com/libp2p/go-libp2p/core/peer"
|
||||
"github.com/multiformats/go-multiaddr"
|
||||
|
||||
"github.com/prysmaticlabs/go-bitfield"
|
||||
)
|
||||
|
||||
func (s *Sentinel) ConnectWithPeer(ctx context.Context, info peer.AddrInfo, skipHandshake bool) (err error) {
|
||||
// ConnectWithPeer is used to attempt to connect and add the peer to our pool
|
||||
// it errors when if fail to connect with the peer, for instance, if it fails the handshake
|
||||
// if it does not return an error, the peer is attempted to be added to the pool
|
||||
func (s *Sentinel) ConnectWithPeer(ctx context.Context, info peer.AddrInfo) (err error) {
|
||||
if info.ID == s.host.ID() {
|
||||
return nil
|
||||
}
|
||||
s.peers.WithPeer(info.ID, func(peer *peers.Peer) {
|
||||
if peer.IsBad() {
|
||||
err = fmt.Errorf("refused to connect to bad peer")
|
||||
}
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
if s.peers.BanStatus(info.ID) {
|
||||
return fmt.Errorf("refused to connect to bad peer")
|
||||
}
|
||||
ctxWithTimeout, cancel := context.WithTimeout(ctx, clparams.MaxDialTimeout)
|
||||
defer cancel()
|
||||
if err := s.host.Connect(ctxWithTimeout, info); err != nil {
|
||||
s.peers.WithPeer(info.ID, func(peer *peers.Peer) {
|
||||
peer.Disconnect(err.Error())
|
||||
})
|
||||
err = s.host.Connect(ctxWithTimeout, info)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// connectWithAllPeers is a helper function used to connect with a list of addrs.
|
||||
// it only returns an error on fail to parse multiaddrs
|
||||
// will print connect with peer errors to trace debug level
|
||||
func (s *Sentinel) connectWithAllPeers(multiAddrs []multiaddr.Multiaddr) error {
|
||||
addrInfos, err := peer.AddrInfosFromP2pAddrs(multiAddrs...)
|
||||
if err != nil {
|
||||
@ -61,7 +45,7 @@ func (s *Sentinel) connectWithAllPeers(multiAddrs []multiaddr.Multiaddr) error {
|
||||
}
|
||||
for _, peerInfo := range addrInfos {
|
||||
go func(peerInfo peer.AddrInfo) {
|
||||
if err := s.ConnectWithPeer(s.ctx, peerInfo, true); err != nil {
|
||||
if err := s.ConnectWithPeer(s.ctx, peerInfo); err != nil {
|
||||
log.Trace("[Sentinel] Could not connect with peer", "err", err)
|
||||
}
|
||||
}(peerInfo)
|
||||
@ -87,7 +71,6 @@ func (s *Sentinel) listenForPeers() {
|
||||
multiAddresses := convertToMultiAddr(enodes)
|
||||
if err := s.connectWithAllPeers(multiAddresses); err != nil {
|
||||
log.Warn("Could not connect to static peers", "reason", err)
|
||||
|
||||
}
|
||||
|
||||
iterator := s.listener.RandomNodes()
|
||||
@ -124,7 +107,7 @@ func (s *Sentinel) listenForPeers() {
|
||||
}
|
||||
|
||||
go func(peerInfo *peer.AddrInfo) {
|
||||
if err := s.ConnectWithPeer(s.ctx, *peerInfo, false); err != nil {
|
||||
if err := s.ConnectWithPeer(s.ctx, *peerInfo); err != nil {
|
||||
log.Trace("[Sentinel] Could not connect with peer", "err", err)
|
||||
}
|
||||
}(peerInfo)
|
||||
@ -161,12 +144,19 @@ func (s *Sentinel) setupENR(
|
||||
func (s *Sentinel) onConnection(net network.Network, conn network.Conn) {
|
||||
go func() {
|
||||
peerId := conn.RemotePeer()
|
||||
invalid := !s.handshaker.ValidatePeer(peerId)
|
||||
if invalid {
|
||||
valid, err := s.handshaker.ValidatePeer(peerId)
|
||||
if err != nil {
|
||||
log.Trace("[sentinel] failed to validate peer:", "err", err)
|
||||
}
|
||||
if !valid {
|
||||
log.Trace("Handshake was unsuccessful")
|
||||
s.peers.WithPeer(peerId, func(peer *peers.Peer) {
|
||||
peer.Disconnect("invalid peer", "bad handshake")
|
||||
})
|
||||
// on handshake fail, we disconnect with said peer, and remove them from our pool
|
||||
s.host.Peerstore().RemovePeer(peerId)
|
||||
s.host.Network().ClosePeer(peerId)
|
||||
s.peers.RemovePeer(peerId)
|
||||
} else {
|
||||
// we were able to succesfully connect, so add this peer to our pool
|
||||
s.peers.AddPeer(peerId)
|
||||
}
|
||||
}()
|
||||
}
|
@ -1,20 +1,19 @@
|
||||
/*
|
||||
Copyright 2022 Erigon-Lightclient contributors
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
// Copyright 2022 Erigon-Caplin contributors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package sentinel
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
@ -23,6 +22,7 @@ import (
|
||||
"github.com/ledgerwatch/erigon/cl/fork"
|
||||
"github.com/ledgerwatch/log/v3"
|
||||
pubsub "github.com/libp2p/go-libp2p-pubsub"
|
||||
"github.com/libp2p/go-libp2p/core/peer"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -181,21 +181,21 @@ func (s *Sentinel) topicScoreParams(topic string) *pubsub.TopicScoreParams {
|
||||
case strings.Contains(topic, string(BeaconBlockTopic)):
|
||||
return s.defaultBlockTopicParams()
|
||||
/*case strings.Contains(topic, GossipAggregateAndProofMessage):
|
||||
return defaultAggregateTopicParams(activeValidators), nil
|
||||
return defaultAggregateTopicParams(activeValidators), nil
|
||||
case strings.Contains(topic, GossipAttestationMessage):
|
||||
return defaultAggregateSubnetTopicParams(activeValidators), nil
|
||||
return defaultAggregateSubnetTopicParams(activeValidators), nil
|
||||
case strings.Contains(topic, GossipSyncCommitteeMessage):
|
||||
return defaultSyncSubnetTopicParams(activeValidators), nil
|
||||
return defaultSyncSubnetTopicParams(activeValidators), nil
|
||||
case strings.Contains(topic, GossipContributionAndProofMessage):
|
||||
return defaultSyncContributionTopicParams(), nil
|
||||
return defaultSyncContributionTopicParams(), nil
|
||||
case strings.Contains(topic, GossipExitMessage):
|
||||
return defaultVoluntaryExitTopicParams(), nil
|
||||
return defaultVoluntaryExitTopicParams(), nil
|
||||
case strings.Contains(topic, GossipProposerSlashingMessage):
|
||||
return defaultProposerSlashingTopicParams(), nil
|
||||
return defaultProposerSlashingTopicParams(), nil
|
||||
case strings.Contains(topic, GossipAttesterSlashingMessage):
|
||||
return defaultAttesterSlashingTopicParams(), nil
|
||||
return defaultAttesterSlashingTopicParams(), nil
|
||||
case strings.Contains(topic, GossipBlsToExecutionChangeMessage):
|
||||
return defaultBlsToExecutionChangeTopicParams(), nil*/
|
||||
return defaultBlsToExecutionChangeTopicParams(), nil*/
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
@ -234,3 +234,89 @@ func (g *GossipManager) Close() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// GossipSubscription abstracts a gossip subscription to write decoded structs.
|
||||
type GossipSubscription struct {
|
||||
gossip_topic GossipTopic
|
||||
host peer.ID
|
||||
ch chan *pubsub.Message
|
||||
ctx context.Context
|
||||
|
||||
topic *pubsub.Topic
|
||||
sub *pubsub.Subscription
|
||||
|
||||
cf context.CancelFunc
|
||||
rf pubsub.RelayCancelFunc
|
||||
|
||||
setup sync.Once
|
||||
stopCh chan struct{}
|
||||
}
|
||||
|
||||
func (sub *GossipSubscription) Listen() (err error) {
|
||||
sub.setup.Do(func() {
|
||||
sub.stopCh = make(chan struct{}, 3)
|
||||
sub.sub, err = sub.topic.Subscribe()
|
||||
if err != nil {
|
||||
err = fmt.Errorf("failed to begin topic %s subscription, err=%w", sub.topic.String(), err)
|
||||
return
|
||||
}
|
||||
var sctx context.Context
|
||||
sctx, sub.cf = context.WithCancel(sub.ctx)
|
||||
go sub.run(sctx, sub.sub, sub.sub.Topic())
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
// calls the cancel func for the subscriber and closes the topic and sub
|
||||
func (s *GossipSubscription) Close() {
|
||||
s.stopCh <- struct{}{}
|
||||
if s.cf != nil {
|
||||
s.cf()
|
||||
}
|
||||
if s.rf != nil {
|
||||
s.rf()
|
||||
}
|
||||
if s.sub != nil {
|
||||
s.sub.Cancel()
|
||||
s.sub = nil
|
||||
}
|
||||
if s.topic != nil {
|
||||
s.topic.Close()
|
||||
s.topic = nil
|
||||
}
|
||||
}
|
||||
|
||||
// this is a helper to begin running the gossip subscription.
|
||||
// function should not be used outside of the constructor for gossip subscription
|
||||
func (s *GossipSubscription) run(ctx context.Context, sub *pubsub.Subscription, topic string) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
log.Error("[Sentinel Gossip] Message Handler Crashed", "err", r)
|
||||
}
|
||||
}()
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case <-s.stopCh:
|
||||
return
|
||||
default:
|
||||
msg, err := sub.Next(ctx)
|
||||
if err != nil {
|
||||
if errors.Is(err, context.Canceled) {
|
||||
return
|
||||
}
|
||||
log.Warn("[Sentinel] fail to decode gossip packet", "err", err, "topic", topic)
|
||||
return
|
||||
}
|
||||
if msg.GetFrom() == s.host {
|
||||
continue
|
||||
}
|
||||
s.ch <- msg
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GossipSubscription) Publish(data []byte) error {
|
||||
return g.topic.Publish(g.ctx, data)
|
||||
}
|
@ -14,7 +14,7 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"github.com/ledgerwatch/erigon/cmd/sentinel/sentinel/communication/ssz_snappy"
|
||||
"github.com/ledgerwatch/erigon/cl/sentinel/communication/ssz_snappy"
|
||||
"github.com/ledgerwatch/log/v3"
|
||||
"github.com/libp2p/go-libp2p/core/network"
|
||||
)
|
@ -17,11 +17,12 @@ import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"github.com/ledgerwatch/erigon/cl/sentinel/communication"
|
||||
"github.com/ledgerwatch/erigon/cl/sentinel/peers"
|
||||
|
||||
"github.com/ledgerwatch/erigon/cl/clparams"
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
"github.com/ledgerwatch/erigon/cl/persistence"
|
||||
"github.com/ledgerwatch/erigon/cmd/sentinel/sentinel/communication"
|
||||
"github.com/ledgerwatch/erigon/cmd/sentinel/sentinel/peers"
|
||||
"github.com/ledgerwatch/log/v3"
|
||||
"github.com/libp2p/go-libp2p/core/host"
|
||||
"github.com/libp2p/go-libp2p/core/network"
|
||||
@ -31,7 +32,6 @@ import (
|
||||
type ConsensusHandlers struct {
|
||||
handlers map[protocol.ID]network.StreamHandler
|
||||
host host.Host
|
||||
peers *peers.Manager
|
||||
metadata *cltypes.Metadata
|
||||
beaconConfig *clparams.BeaconChainConfig
|
||||
genesisConfig *clparams.GenesisConfig
|
||||
@ -46,9 +46,8 @@ const (
|
||||
)
|
||||
|
||||
func NewConsensusHandlers(ctx context.Context, db persistence.RawBeaconBlockChain, host host.Host,
|
||||
peers *peers.Manager, beaconConfig *clparams.BeaconChainConfig, genesisConfig *clparams.GenesisConfig, metadata *cltypes.Metadata) *ConsensusHandlers {
|
||||
peers *peers.Pool, beaconConfig *clparams.BeaconChainConfig, genesisConfig *clparams.GenesisConfig, metadata *cltypes.Metadata) *ConsensusHandlers {
|
||||
c := &ConsensusHandlers{
|
||||
peers: peers,
|
||||
host: host,
|
||||
metadata: metadata,
|
||||
beaconDB: db,
|
@ -16,7 +16,7 @@ package handlers
|
||||
import (
|
||||
"github.com/ledgerwatch/erigon/cl/clparams"
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
"github.com/ledgerwatch/erigon/cmd/sentinel/sentinel/communication/ssz_snappy"
|
||||
"github.com/ledgerwatch/erigon/cl/sentinel/communication/ssz_snappy"
|
||||
"github.com/libp2p/go-libp2p/core/network"
|
||||
)
|
||||
|
@ -3,17 +3,19 @@ package handshake
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"sync"
|
||||
|
||||
communication2 "github.com/ledgerwatch/erigon/cl/sentinel/communication"
|
||||
"github.com/ledgerwatch/erigon/cl/sentinel/communication/ssz_snappy"
|
||||
"github.com/ledgerwatch/erigon/cl/sentinel/httpreqresp"
|
||||
|
||||
"github.com/ledgerwatch/erigon/cl/clparams"
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
"github.com/ledgerwatch/erigon/cl/fork"
|
||||
"github.com/ledgerwatch/erigon/cmd/sentinel/sentinel/communication"
|
||||
"github.com/ledgerwatch/erigon/cmd/sentinel/sentinel/communication/ssz_snappy"
|
||||
"github.com/ledgerwatch/erigon/common"
|
||||
"github.com/libp2p/go-libp2p/core/host"
|
||||
"github.com/libp2p/go-libp2p/core/peer"
|
||||
"go.uber.org/zap/buffer"
|
||||
)
|
||||
|
||||
// HandShaker is the data type which will handle handshakes and determine if
|
||||
@ -23,17 +25,17 @@ type HandShaker struct {
|
||||
// Status object to send over.
|
||||
status *cltypes.Status // Contains status object for handshakes
|
||||
set bool
|
||||
host host.Host
|
||||
handler http.Handler
|
||||
genesisConfig *clparams.GenesisConfig
|
||||
beaconConfig *clparams.BeaconChainConfig
|
||||
|
||||
mu sync.Mutex
|
||||
}
|
||||
|
||||
func New(ctx context.Context, genesisConfig *clparams.GenesisConfig, beaconConfig *clparams.BeaconChainConfig, host host.Host) *HandShaker {
|
||||
func New(ctx context.Context, genesisConfig *clparams.GenesisConfig, beaconConfig *clparams.BeaconChainConfig, handler http.Handler) *HandShaker {
|
||||
return &HandShaker{
|
||||
ctx: ctx,
|
||||
host: host,
|
||||
handler: handler,
|
||||
genesisConfig: genesisConfig,
|
||||
beaconConfig: beaconConfig,
|
||||
status: &cltypes.Status{},
|
||||
@ -62,31 +64,41 @@ func (h *HandShaker) IsSet() bool {
|
||||
return h.set
|
||||
}
|
||||
|
||||
func (h *HandShaker) ValidatePeer(id peer.ID) bool {
|
||||
func (h *HandShaker) ValidatePeer(id peer.ID) (bool, error) {
|
||||
// Unprotected if it is not set
|
||||
if !h.IsSet() {
|
||||
return true
|
||||
return true, nil
|
||||
}
|
||||
status := h.Status()
|
||||
// Encode our status
|
||||
var buffer buffer.Buffer
|
||||
if err := ssz_snappy.EncodeAndWrite(&buffer, status); err != nil {
|
||||
return false
|
||||
buf := new(bytes.Buffer)
|
||||
if err := ssz_snappy.EncodeAndWrite(buf, status); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
data := common.CopyBytes(buffer.Bytes())
|
||||
response, errResponse, err := communication.SendRequestRawToPeer(h.ctx, h.host, data, communication.StatusProtocolV1, id)
|
||||
if err != nil || errResponse > 0 {
|
||||
return false
|
||||
req, err := http.NewRequest("GET", "http://service.internal/", buf)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
req.Header.Set("REQRESP-PEER-ID", id.String())
|
||||
req.Header.Set("REQRESP-TOPIC", communication2.StatusProtocolV1)
|
||||
resp, err := httpreqresp.Do(h.handler, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.Header.Get("REQRESP-RESPONSE-CODE") != "0" {
|
||||
a, _ := io.ReadAll(resp.Body)
|
||||
//TODO: proper errors
|
||||
return false, fmt.Errorf("handshake error: %s", string(a))
|
||||
}
|
||||
responseStatus := &cltypes.Status{}
|
||||
|
||||
if err := ssz_snappy.DecodeAndReadNoForkDigest(bytes.NewReader(response), responseStatus, clparams.Phase0Version); err != nil {
|
||||
return false
|
||||
if err := ssz_snappy.DecodeAndReadNoForkDigest(resp.Body, responseStatus, clparams.Phase0Version); err != nil {
|
||||
return false, nil
|
||||
}
|
||||
forkDigest, err := fork.ComputeForkDigest(h.beaconConfig, h.genesisConfig)
|
||||
if err != nil {
|
||||
return false
|
||||
return false, nil
|
||||
}
|
||||
return responseStatus.ForkDigest == forkDigest
|
||||
return responseStatus.ForkDigest == forkDigest, nil
|
||||
}
|
122
cl/sentinel/httpreqresp/server.go
Normal file
122
cl/sentinel/httpreqresp/server.go
Normal file
@ -0,0 +1,122 @@
|
||||
// package httpreqresp encapsulates eth2 beacon chain resp-resp into http
|
||||
package httpreqresp
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/libp2p/go-libp2p/core/host"
|
||||
"github.com/libp2p/go-libp2p/core/peer"
|
||||
"github.com/libp2p/go-libp2p/core/protocol"
|
||||
)
|
||||
|
||||
const (
|
||||
ResponseCodeHeader = "Reqresp-Response-Code"
|
||||
PeerIdHeader = "Reqresp-Peer-Id"
|
||||
TopicHeader = "Reqresp-Topic"
|
||||
)
|
||||
|
||||
// Do performs an http request against the http handler.
|
||||
// NOTE: this is actually very similar to the http.RoundTripper interface... maybe we should investigate using that.
|
||||
/*
|
||||
|
||||
the following headers have meaning when passed in to the request:
|
||||
|
||||
REQRESP-PEER-ID - the peer id to target for the request
|
||||
REQRESP-TOPIC - the topic to request with
|
||||
REQRESP-EXPECTED-CHUNKS - this is an integer, which will be multiplied by 10 to calculate the amount of seconds the peer has to respond with all the data
|
||||
*/
|
||||
func Do(handler http.Handler, r *http.Request) (*http.Response, error) {
|
||||
// TODO: there potentially extra alloc here (responses are bufferd)
|
||||
// is that a big deal? not sure. maybe can reuse these buffers since they are read once (and known when close) if so
|
||||
ans := make(chan *http.Response)
|
||||
go func() {
|
||||
res := httptest.NewRecorder()
|
||||
handler.ServeHTTP(res, r)
|
||||
// linter does not know we are passing the resposne through channel.
|
||||
// nolint: bodyclose
|
||||
resp := res.Result()
|
||||
ans <- resp
|
||||
}()
|
||||
select {
|
||||
case res := <-ans:
|
||||
return res, nil
|
||||
case <-r.Context().Done():
|
||||
return nil, r.Context().Err()
|
||||
}
|
||||
}
|
||||
|
||||
// Handles a request
|
||||
func NewRequestHandler(host host.Host) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
// get the peer parameters
|
||||
peerIdBase58 := r.Header.Get("REQRESP-PEER-ID")
|
||||
topic := r.Header.Get("REQRESP-TOPIC")
|
||||
chunkCount := r.Header.Get("REQRESP-EXPECTED-CHUNKS")
|
||||
chunks, _ := strconv.Atoi(chunkCount)
|
||||
// some sanity checking on chunks
|
||||
if chunks < 1 {
|
||||
chunks = 1
|
||||
}
|
||||
// idk why this would happen, so lets make sure it doesnt. future-proofing from bad input
|
||||
if chunks > 512 {
|
||||
chunks = 512
|
||||
}
|
||||
// read the base58 encoded peer id to know which we are trying to dial
|
||||
peerId, err := peer.Decode(peerIdBase58)
|
||||
if err != nil {
|
||||
http.Error(w, "Invalid Peer Id", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
// we can't connect to the peer - so we should disconnect them. send a code 4xx
|
||||
stream, err := host.NewStream(r.Context(), peerId, protocol.ID(topic))
|
||||
if err != nil {
|
||||
http.Error(w, "Can't Connect to Peer: "+err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
defer stream.Close()
|
||||
// this write deadline is not part of the eth p2p spec, but we are implying it.
|
||||
stream.SetWriteDeadline(time.Now().Add(5 * time.Second))
|
||||
if r.Body != nil && r.ContentLength > 0 {
|
||||
_, err := io.Copy(stream, r.Body)
|
||||
if err != nil {
|
||||
http.Error(w, "Processing Stream: "+err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
}
|
||||
err = stream.CloseWrite()
|
||||
if err != nil {
|
||||
http.Error(w, "Close Write Side: "+err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
code := make([]byte, 1)
|
||||
// we have 5 seconds to read the next byte. this is the 5 TTFB_TIMEOUT in the spec
|
||||
stream.SetReadDeadline(time.Now().Add(5 * time.Second))
|
||||
_, err = io.ReadFull(stream, code)
|
||||
if err != nil {
|
||||
http.Error(w, "Read Code: "+err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
// this is not neccesary, but seems like the right thing to do
|
||||
w.Header().Set("CONTENT-TYPE", "application/octet-stream")
|
||||
w.Header().Set("CONTENT-ENCODING", "snappy/stream")
|
||||
// add the response code & headers
|
||||
w.Header().Set("REQRESP-RESPONSE-CODE", strconv.Itoa(int(code[0])))
|
||||
w.Header().Set("REQRESP-PEER-ID", peerIdBase58)
|
||||
w.Header().Set("REQRESP-TOPIC", topic)
|
||||
// the deadline is 10 * expected chunk count, which the user can send. otherwise we will only wait 10 seconds
|
||||
// this is technically incorrect, and more aggressive than the network might like.
|
||||
stream.SetReadDeadline(time.Now().Add(10 * time.Second * time.Duration(chunks)))
|
||||
// copy the data now to the stream
|
||||
// the first write to w will call code 200, so we do not need to
|
||||
_, err = io.Copy(w, stream)
|
||||
if err != nil {
|
||||
http.Error(w, "Reading Stream Response: "+err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
66
cl/sentinel/libp2p_settings.go
Normal file
66
cl/sentinel/libp2p_settings.go
Normal file
@ -0,0 +1,66 @@
|
||||
package sentinel
|
||||
|
||||
import (
|
||||
"math"
|
||||
"time"
|
||||
|
||||
pubsub "github.com/libp2p/go-libp2p-pubsub"
|
||||
"github.com/libp2p/go-libp2p/core/peer"
|
||||
)
|
||||
|
||||
// determines the decay rate from the provided time period till
|
||||
// the decayToZero value. Ex: ( 1 -> 0.01)
|
||||
func (s *Sentinel) scoreDecay(totalDurationDecay time.Duration) float64 {
|
||||
numOfTimes := totalDurationDecay / s.oneSlotDuration()
|
||||
return math.Pow(decayToZero, 1/float64(numOfTimes))
|
||||
}
|
||||
|
||||
func (s *Sentinel) pubsubOptions() []pubsub.Option {
|
||||
thresholds := &pubsub.PeerScoreThresholds{
|
||||
GossipThreshold: -4000,
|
||||
PublishThreshold: -8000,
|
||||
GraylistThreshold: -16000,
|
||||
AcceptPXThreshold: 100,
|
||||
OpportunisticGraftThreshold: 5,
|
||||
}
|
||||
scoreParams := &pubsub.PeerScoreParams{
|
||||
Topics: make(map[string]*pubsub.TopicScoreParams),
|
||||
TopicScoreCap: 32.72,
|
||||
AppSpecificScore: func(p peer.ID) float64 {
|
||||
return 0
|
||||
},
|
||||
AppSpecificWeight: 1,
|
||||
IPColocationFactorWeight: -35.11,
|
||||
IPColocationFactorThreshold: 10,
|
||||
IPColocationFactorWhitelist: nil,
|
||||
BehaviourPenaltyWeight: -15.92,
|
||||
BehaviourPenaltyThreshold: 6,
|
||||
BehaviourPenaltyDecay: s.scoreDecay(10 * s.oneEpochDuration()), // 10 epochs
|
||||
DecayInterval: s.oneSlotDuration(),
|
||||
DecayToZero: decayToZero,
|
||||
RetainScore: 100 * s.oneEpochDuration(), // Retain for 100 epochs
|
||||
}
|
||||
pubsubQueueSize := 600
|
||||
psOpts := []pubsub.Option{
|
||||
pubsub.WithMessageSignaturePolicy(pubsub.StrictNoSign),
|
||||
pubsub.WithMessageIdFn(s.msgId),
|
||||
pubsub.WithNoAuthor(),
|
||||
pubsub.WithPeerOutboundQueueSize(pubsubQueueSize),
|
||||
pubsub.WithMaxMessageSize(int(s.cfg.NetworkConfig.GossipMaxSizeBellatrix)),
|
||||
pubsub.WithValidateQueueSize(pubsubQueueSize),
|
||||
pubsub.WithPeerScore(scoreParams, thresholds),
|
||||
pubsub.WithGossipSubParams(pubsubGossipParam()),
|
||||
}
|
||||
return psOpts
|
||||
}
|
||||
|
||||
// creates a custom gossipsub parameter set.
|
||||
func pubsubGossipParam() pubsub.GossipSubParams {
|
||||
gParams := pubsub.DefaultGossipSubParams()
|
||||
gParams.Dlo = gossipSubDlo
|
||||
gParams.D = gossipSubD
|
||||
gParams.HeartbeatInterval = gossipSubHeartbeatInterval
|
||||
gParams.HistoryLength = gossipSubMcacheLen
|
||||
gParams.HistoryGossip = gossipSubMcacheGossip
|
||||
return gParams
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
package peers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/core/state/lru"
|
||||
"github.com/libp2p/go-libp2p/core/host"
|
||||
"github.com/libp2p/go-libp2p/core/peer"
|
||||
)
|
||||
|
||||
const (
|
||||
maxBadPeers = 50000
|
||||
maxPeerRecordSize = 1000
|
||||
DefaultMaxPeers = 33
|
||||
MaxBadResponses = 50
|
||||
)
|
||||
|
||||
func newPeer() *Peer {
|
||||
return &Peer{
|
||||
lastTouched: time.Now(),
|
||||
working: make(chan struct{}),
|
||||
}
|
||||
}
|
||||
|
||||
type Manager struct {
|
||||
host host.Host
|
||||
peers *lru.Cache[peer.ID, *Peer]
|
||||
peerTimeout time.Duration
|
||||
|
||||
mu sync.Mutex
|
||||
}
|
||||
|
||||
func NewManager(ctx context.Context, host host.Host) *Manager {
|
||||
c, err := lru.NewWithEvict("beacon_peer_manager", 500, func(i peer.ID, p *Peer) {
|
||||
p.Disconnect("booted for inactivity")
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
m := &Manager{
|
||||
peerTimeout: 8 * time.Hour,
|
||||
peers: c,
|
||||
host: host,
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
func (m *Manager) GetPeer(id peer.ID) (peer *Peer) {
|
||||
m.mu.Lock()
|
||||
p, ok := m.peers.Get(id)
|
||||
if !ok {
|
||||
p = &Peer{
|
||||
pid: id,
|
||||
working: make(chan struct{}, 1),
|
||||
m: m,
|
||||
penalties: 0,
|
||||
banned: false,
|
||||
}
|
||||
m.peers.Add(id, p)
|
||||
}
|
||||
p.lastTouched = time.Now()
|
||||
m.mu.Unlock()
|
||||
return p
|
||||
}
|
@ -1,154 +0,0 @@
|
||||
package peers
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/ledgerwatch/log/v3"
|
||||
"github.com/libp2p/go-libp2p/core/peer"
|
||||
)
|
||||
|
||||
const USERAGENT_UNKNOWN = "unknown"
|
||||
|
||||
type PeeredObject[T any] struct {
|
||||
Peer string
|
||||
Data T
|
||||
}
|
||||
|
||||
// Record Peer data.
|
||||
type Peer struct {
|
||||
penalties int
|
||||
banned bool
|
||||
|
||||
// request info
|
||||
lastRequest time.Time
|
||||
successCount int
|
||||
useCount int
|
||||
// gc data
|
||||
lastTouched time.Time
|
||||
|
||||
mu sync.Mutex
|
||||
|
||||
// peer id
|
||||
pid peer.ID
|
||||
|
||||
// acts as the mutex for making requests. channel used to avoid use of TryLock
|
||||
working chan struct{}
|
||||
// backref to the manager that owns this peer
|
||||
m *Manager
|
||||
}
|
||||
|
||||
func (p *Peer) do(fn func(p *Peer)) {
|
||||
if fn == nil {
|
||||
return
|
||||
}
|
||||
p.mu.Lock()
|
||||
defer p.mu.Unlock()
|
||||
fn(p)
|
||||
}
|
||||
|
||||
func (p *Peer) UserAgent() string {
|
||||
rawVer, err := p.m.host.Peerstore().Get(p.pid, "AgentVersion")
|
||||
if err == nil {
|
||||
if str, ok := rawVer.(string); ok {
|
||||
return str
|
||||
}
|
||||
}
|
||||
return USERAGENT_UNKNOWN
|
||||
}
|
||||
|
||||
func (p *Peer) Penalize() {
|
||||
log.Trace("[Sentinel Peers] peer penalized", "peer-id", p.pid)
|
||||
p.do(func(p *Peer) {
|
||||
p.penalties++
|
||||
})
|
||||
}
|
||||
|
||||
func (p *Peer) Forgive() {
|
||||
log.Trace("[Sentinel Peers] peer forgiven", "peer-id", p.pid)
|
||||
p.do(func(p *Peer) {
|
||||
if p.penalties > 0 {
|
||||
p.penalties--
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (p *Peer) MarkUsed() {
|
||||
p.do(func(p *Peer) {
|
||||
p.useCount++
|
||||
p.lastRequest = time.Now()
|
||||
})
|
||||
log.Trace("[Sentinel Peers] peer used", "peer-id", p.pid, "uses", p.useCount)
|
||||
}
|
||||
|
||||
func (p *Peer) MarkReplied() {
|
||||
p.do(func(p *Peer) {
|
||||
p.successCount++
|
||||
})
|
||||
log.Trace("[Sentinel Peers] peer replied", "peer-id", p.pid, "uses", p.useCount, "success", p.successCount)
|
||||
}
|
||||
|
||||
func (p *Peer) IsAvailable() (available bool) {
|
||||
p.mu.Lock()
|
||||
defer p.mu.Unlock()
|
||||
if p.banned {
|
||||
return false
|
||||
}
|
||||
if p.penalties > MaxBadResponses {
|
||||
return false
|
||||
}
|
||||
if time.Now().Sub(p.lastRequest) > 0*time.Second {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (p *Peer) IsBad() (bad bool) {
|
||||
p.mu.Lock()
|
||||
defer p.mu.Unlock()
|
||||
if p.banned {
|
||||
bad = true
|
||||
return
|
||||
}
|
||||
bad = p.penalties > MaxBadResponses
|
||||
return
|
||||
}
|
||||
|
||||
var skipReasons = []string{
|
||||
"bad handshake",
|
||||
"context",
|
||||
"security protocol",
|
||||
"connect:",
|
||||
"dial backoff",
|
||||
}
|
||||
|
||||
func anySetInString(set []string, in string) bool {
|
||||
for _, v := range skipReasons {
|
||||
if strings.Contains(in, v) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (p *Peer) Disconnect(reason ...string) {
|
||||
rzn := strings.Join(reason, " ")
|
||||
if !anySetInString(skipReasons, rzn) {
|
||||
log.Trace("[Sentinel Peers] disconnecting from peer", "peer-id", p.pid, "reason", strings.Join(reason, " "))
|
||||
}
|
||||
p.m.host.Peerstore().RemovePeer(p.pid)
|
||||
p.m.host.Network().ClosePeer(p.pid)
|
||||
p.do(func(p *Peer) {
|
||||
p.penalties = 0
|
||||
})
|
||||
}
|
||||
|
||||
func (p *Peer) Ban(reason ...string) {
|
||||
log.Debug("[Sentinel Peers] bad peers has been banned", "peer-id", p.pid, "reason", strings.Join(reason, " "))
|
||||
p.do(func(p *Peer) {
|
||||
p.banned = true
|
||||
})
|
||||
p.Disconnect(reason...)
|
||||
return
|
||||
}
|
13
cl/sentinel/peers/peers.go
Normal file
13
cl/sentinel/peers/peers.go
Normal file
@ -0,0 +1,13 @@
|
||||
package peers
|
||||
|
||||
const (
|
||||
maxBadPeers = 50000
|
||||
maxPeerRecordSize = 1000
|
||||
DefaultMaxPeers = 64
|
||||
MaxBadResponses = 50
|
||||
)
|
||||
|
||||
type PeeredObject[T any] struct {
|
||||
Peer string
|
||||
Data T
|
||||
}
|
141
cl/sentinel/peers/pool.go
Normal file
141
cl/sentinel/peers/pool.go
Normal file
@ -0,0 +1,141 @@
|
||||
package peers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/ledgerwatch/erigon-lib/common/ring"
|
||||
"github.com/libp2p/go-libp2p/core/peer"
|
||||
)
|
||||
|
||||
// Item is an item in the pool
|
||||
type Item struct {
|
||||
id peer.ID
|
||||
score atomic.Int64
|
||||
uses int
|
||||
}
|
||||
|
||||
func (i *Item) Id() peer.ID {
|
||||
return i.id
|
||||
}
|
||||
|
||||
func (i *Item) String() string {
|
||||
return i.id.String()
|
||||
}
|
||||
|
||||
func (i *Item) Score() int {
|
||||
return int(i.score.Load())
|
||||
}
|
||||
|
||||
func (i *Item) Add(n int) int {
|
||||
return int(i.score.Add(int64(n)))
|
||||
}
|
||||
|
||||
// PeerPool is a pool of peers
|
||||
type Pool struct {
|
||||
|
||||
// allowedPeers are the peers that are allowed.
|
||||
// peers not on this list will be silently discarded
|
||||
// when returned, and skipped when requesting
|
||||
peerData map[peer.ID]*Item
|
||||
|
||||
bannedPeers map[peer.ID]struct{}
|
||||
queue *ring.Buffer[*Item]
|
||||
|
||||
mu sync.Mutex
|
||||
}
|
||||
|
||||
func NewPool() *Pool {
|
||||
return &Pool{
|
||||
peerData: make(map[peer.ID]*Item),
|
||||
bannedPeers: map[peer.ID]struct{}{},
|
||||
queue: ring.NewBuffer[*Item](0, 1024),
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Pool) BanStatus(pid peer.ID) bool {
|
||||
_, ok := p.bannedPeers[pid]
|
||||
return ok
|
||||
}
|
||||
|
||||
func (p *Pool) AddPeer(pid peer.ID) {
|
||||
p.mu.Lock()
|
||||
defer p.mu.Unlock()
|
||||
// if peer banned, return immediately
|
||||
if _, ok := p.bannedPeers[pid]; ok {
|
||||
return
|
||||
}
|
||||
// if peer already here, return immediately
|
||||
if _, ok := p.peerData[pid]; ok {
|
||||
return
|
||||
}
|
||||
newItem := &Item{
|
||||
id: pid,
|
||||
}
|
||||
p.peerData[pid] = newItem
|
||||
// add it to our queue as a new item
|
||||
p.queue.PushBack(newItem)
|
||||
}
|
||||
|
||||
func (p *Pool) SetBanStatus(pid peer.ID, banned bool) {
|
||||
p.mu.Lock()
|
||||
defer p.mu.Unlock()
|
||||
if banned {
|
||||
p.bannedPeers[pid] = struct{}{}
|
||||
delete(p.peerData, pid)
|
||||
} else {
|
||||
delete(p.bannedPeers, pid)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Pool) RemovePeer(pid peer.ID) {
|
||||
p.mu.Lock()
|
||||
defer p.mu.Unlock()
|
||||
delete(p.peerData, pid)
|
||||
}
|
||||
|
||||
// returnPeer is an internal function to return per to the pool. assume has lock
|
||||
func (p *Pool) returnPeer(i *Item) {
|
||||
// if peer not in our map, return and do not return peer
|
||||
if _, ok := p.peerData[i.id]; !ok {
|
||||
return
|
||||
}
|
||||
// append peer to the end of our ring buffer
|
||||
p.queue.PushBack(i)
|
||||
}
|
||||
|
||||
// nextPeer gets next peer, skipping bad peers. assume has lock
|
||||
func (p *Pool) nextPeer() (i *Item, ok bool) {
|
||||
val, ok := p.queue.PopFront()
|
||||
if !ok {
|
||||
return nil, false
|
||||
}
|
||||
// if peer been banned, get next peer
|
||||
if _, ok := p.bannedPeers[val.id]; ok {
|
||||
return p.nextPeer()
|
||||
}
|
||||
// if peer not in set, get next peer
|
||||
if _, ok := p.peerData[val.id]; !ok {
|
||||
return p.nextPeer()
|
||||
}
|
||||
return val, true
|
||||
}
|
||||
|
||||
// Request a peer from the pool
|
||||
// caller MUST call the done function when done with peer IFF err != nil
|
||||
func (p *Pool) Request() (pid *Item, done func(), err error) {
|
||||
p.mu.Lock()
|
||||
defer p.mu.Unlock()
|
||||
//grab a peer from our ringbuffer
|
||||
val, ok := p.queue.PopFront()
|
||||
if !ok {
|
||||
return nil, nil, fmt.Errorf("no peers? ( :( > ")
|
||||
}
|
||||
return val, func() {
|
||||
p.mu.Lock()
|
||||
defer p.mu.Unlock()
|
||||
val.uses = val.uses + 1
|
||||
p.returnPeer(val)
|
||||
}, nil
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
## wip
|
||||
|
||||
|
||||
this is work in progress
|
@ -17,15 +17,18 @@ import (
|
||||
"context"
|
||||
"crypto/ecdsa"
|
||||
"fmt"
|
||||
"math"
|
||||
"net"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/ledgerwatch/erigon/cl/sentinel/handlers"
|
||||
"github.com/ledgerwatch/erigon/cl/sentinel/handshake"
|
||||
"github.com/ledgerwatch/erigon/cl/sentinel/httpreqresp"
|
||||
"github.com/ledgerwatch/erigon/cl/sentinel/peers"
|
||||
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
"github.com/ledgerwatch/erigon/cl/persistence"
|
||||
"github.com/ledgerwatch/erigon/cmd/sentinel/sentinel/handlers"
|
||||
"github.com/ledgerwatch/erigon/cmd/sentinel/sentinel/handshake"
|
||||
"github.com/ledgerwatch/erigon/cmd/sentinel/sentinel/peers"
|
||||
"github.com/ledgerwatch/erigon/crypto"
|
||||
"github.com/ledgerwatch/erigon/p2p/discover"
|
||||
"github.com/ledgerwatch/erigon/p2p/enode"
|
||||
@ -59,12 +62,15 @@ const (
|
||||
)
|
||||
|
||||
type Sentinel struct {
|
||||
started bool
|
||||
listener *discover.UDPv5 // this is us in the network.
|
||||
ctx context.Context
|
||||
host host.Host
|
||||
cfg *SentinelConfig
|
||||
peers *peers.Manager
|
||||
started bool
|
||||
listener *discover.UDPv5 // this is us in the network.
|
||||
ctx context.Context
|
||||
host host.Host
|
||||
cfg *SentinelConfig
|
||||
peers *peers.Pool
|
||||
|
||||
httpApi http.Handler
|
||||
|
||||
metadataV2 *cltypes.Metadata
|
||||
handshaker *handshake.HandShaker
|
||||
|
||||
@ -169,63 +175,6 @@ func (s *Sentinel) createListener() (*discover.UDPv5, error) {
|
||||
return net, err
|
||||
}
|
||||
|
||||
// creates a custom gossipsub parameter set.
|
||||
func pubsubGossipParam() pubsub.GossipSubParams {
|
||||
gParams := pubsub.DefaultGossipSubParams()
|
||||
gParams.Dlo = gossipSubDlo
|
||||
gParams.D = gossipSubD
|
||||
gParams.HeartbeatInterval = gossipSubHeartbeatInterval
|
||||
gParams.HistoryLength = gossipSubMcacheLen
|
||||
gParams.HistoryGossip = gossipSubMcacheGossip
|
||||
return gParams
|
||||
}
|
||||
|
||||
// determines the decay rate from the provided time period till
|
||||
// the decayToZero value. Ex: ( 1 -> 0.01)
|
||||
func (s *Sentinel) scoreDecay(totalDurationDecay time.Duration) float64 {
|
||||
numOfTimes := totalDurationDecay / s.oneSlotDuration()
|
||||
return math.Pow(decayToZero, 1/float64(numOfTimes))
|
||||
}
|
||||
|
||||
func (s *Sentinel) pubsubOptions() []pubsub.Option {
|
||||
thresholds := &pubsub.PeerScoreThresholds{
|
||||
GossipThreshold: -4000,
|
||||
PublishThreshold: -8000,
|
||||
GraylistThreshold: -16000,
|
||||
AcceptPXThreshold: 100,
|
||||
OpportunisticGraftThreshold: 5,
|
||||
}
|
||||
scoreParams := &pubsub.PeerScoreParams{
|
||||
Topics: make(map[string]*pubsub.TopicScoreParams),
|
||||
TopicScoreCap: 32.72,
|
||||
AppSpecificScore: func(p peer.ID) float64 {
|
||||
return 0
|
||||
},
|
||||
AppSpecificWeight: 1,
|
||||
IPColocationFactorWeight: -35.11,
|
||||
IPColocationFactorThreshold: 10,
|
||||
IPColocationFactorWhitelist: nil,
|
||||
BehaviourPenaltyWeight: -15.92,
|
||||
BehaviourPenaltyThreshold: 6,
|
||||
BehaviourPenaltyDecay: s.scoreDecay(10 * s.oneEpochDuration()), // 10 epochs
|
||||
DecayInterval: s.oneSlotDuration(),
|
||||
DecayToZero: decayToZero,
|
||||
RetainScore: 100 * s.oneEpochDuration(), // Retain for 100 epochs
|
||||
}
|
||||
pubsubQueueSize := 600
|
||||
psOpts := []pubsub.Option{
|
||||
pubsub.WithMessageSignaturePolicy(pubsub.StrictNoSign),
|
||||
pubsub.WithMessageIdFn(s.msgId),
|
||||
pubsub.WithNoAuthor(),
|
||||
pubsub.WithPeerOutboundQueueSize(pubsubQueueSize),
|
||||
pubsub.WithMaxMessageSize(int(s.cfg.NetworkConfig.GossipMaxSizeBellatrix)),
|
||||
pubsub.WithValidateQueueSize(pubsubQueueSize),
|
||||
pubsub.WithPeerScore(scoreParams, thresholds),
|
||||
pubsub.WithGossipSubParams(pubsubGossipParam()),
|
||||
}
|
||||
return psOpts
|
||||
}
|
||||
|
||||
// This is just one of the examples from the libp2p repository.
|
||||
func New(
|
||||
ctx context.Context,
|
||||
@ -263,20 +212,17 @@ func New(
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if s.metrics {
|
||||
|
||||
str, err := rcmgrObs.NewStatsTraceReporter()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rmgr, err := rcmgr.NewResourceManager(rcmgr.NewFixedLimiter(rcmgr.DefaultLimits.AutoScale()), rcmgr.WithTraceReporter(str))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
opts = append(opts, libp2p.ResourceManager(rmgr))
|
||||
str, err := rcmgrObs.NewStatsTraceReporter()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rmgr, err := rcmgr.NewResourceManager(rcmgr.NewFixedLimiter(rcmgr.DefaultLimits.AutoScale()), rcmgr.WithTraceReporter(str))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
opts = append(opts, libp2p.ResourceManager(rmgr))
|
||||
|
||||
gater, err := NewGater(cfg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -288,11 +234,16 @@ func New(
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
s.handshaker = handshake.New(ctx, cfg.GenesisConfig, cfg.BeaconConfig, host)
|
||||
|
||||
s.host = host
|
||||
s.peers = peers.NewManager(ctx, s.host)
|
||||
|
||||
s.peers = peers.NewPool()
|
||||
|
||||
mux := chi.NewRouter()
|
||||
// mux := httpreqresp.NewRequestHandler(host)
|
||||
mux.Get("/", httpreqresp.NewRequestHandler(host))
|
||||
s.httpApi = mux
|
||||
|
||||
s.handshaker = handshake.New(ctx, cfg.GenesisConfig, cfg.BeaconConfig, s.httpApi)
|
||||
|
||||
pubsub.TimeCacheDuration = 550 * gossipSubHeartbeatInterval
|
||||
s.pubsub, err = pubsub.NewGossipSub(s.ctx, s.host, s.pubsubOptions()...)
|
||||
@ -303,6 +254,10 @@ func New(
|
||||
return s, nil
|
||||
}
|
||||
|
||||
func (s *Sentinel) ReqRespHandler() http.Handler {
|
||||
return s.httpApi
|
||||
}
|
||||
|
||||
func (s *Sentinel) RecvGossip() <-chan *pubsub.Message {
|
||||
return s.subManager.Recv()
|
||||
}
|
||||
@ -323,6 +278,10 @@ func (s *Sentinel) Start() error {
|
||||
// Configuring handshake
|
||||
s.host.Network().Notify(&network.NotifyBundle{
|
||||
ConnectedF: s.onConnection,
|
||||
DisconnectedF: func(n network.Network, c network.Conn) {
|
||||
peerId := c.RemotePeer()
|
||||
s.peers.RemovePeer(peerId)
|
||||
},
|
||||
})
|
||||
s.subManager = NewGossipManager(s.ctx)
|
||||
|
||||
@ -360,7 +319,7 @@ func (s *Sentinel) Host() host.Host {
|
||||
return s.host
|
||||
}
|
||||
|
||||
func (s *Sentinel) Peers() *peers.Manager {
|
||||
func (s *Sentinel) Peers() *peers.Pool {
|
||||
return s.peers
|
||||
}
|
||||
|
@ -1,21 +1,25 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/ledgerwatch/erigon/cl/sentinel"
|
||||
"github.com/ledgerwatch/erigon/cl/sentinel/httpreqresp"
|
||||
"github.com/ledgerwatch/erigon/cl/sentinel/peers"
|
||||
|
||||
"github.com/ledgerwatch/erigon-lib/gointerfaces"
|
||||
sentinelrpc "github.com/ledgerwatch/erigon-lib/gointerfaces/sentinel"
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
"github.com/ledgerwatch/erigon/cl/utils"
|
||||
"github.com/ledgerwatch/erigon/cmd/sentinel/sentinel"
|
||||
"github.com/ledgerwatch/erigon/cmd/sentinel/sentinel/communication"
|
||||
"github.com/ledgerwatch/erigon/cmd/sentinel/sentinel/peers"
|
||||
"github.com/ledgerwatch/log/v3"
|
||||
pubsub "github.com/libp2p/go-libp2p-pubsub"
|
||||
"github.com/libp2p/go-libp2p/core/peer"
|
||||
@ -56,21 +60,17 @@ func extractBlobSideCarIndex(topic string) int {
|
||||
//BanPeer(context.Context, *Peer) (*EmptyMessage, error)
|
||||
|
||||
func (s *SentinelServer) BanPeer(_ context.Context, p *sentinelrpc.Peer) (*sentinelrpc.EmptyMessage, error) {
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
var pid peer.ID
|
||||
if err := pid.UnmarshalText([]byte(p.Pid)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s.sentinel.Peers().WithPeer(pid, func(peer *peers.Peer) {
|
||||
peer.Ban()
|
||||
})
|
||||
s.sentinel.Peers().SetBanStatus(pid, true)
|
||||
s.sentinel.Host().Peerstore().RemovePeer(pid)
|
||||
s.sentinel.Host().Network().ClosePeer(pid)
|
||||
return &sentinelrpc.EmptyMessage{}, nil
|
||||
}
|
||||
|
||||
func (s *SentinelServer) PublishGossip(_ context.Context, msg *sentinelrpc.GossipData) (*sentinelrpc.EmptyMessage, error) {
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
manager := s.sentinel.GossipManager()
|
||||
// Snappify payload before sending it to gossip
|
||||
compressedData := utils.CompressSnappy(msg.Data)
|
||||
@ -146,61 +146,102 @@ func (s *SentinelServer) withTimeoutCtx(pctx context.Context, dur time.Duration)
|
||||
return ctx, cn
|
||||
}
|
||||
|
||||
func (s *SentinelServer) requestPeer(ctx context.Context, pid peer.ID, req *sentinelrpc.RequestData) (*sentinelrpc.ResponseData, error) {
|
||||
// prepare the http request
|
||||
httpReq, err := http.NewRequest("GET", "http://service.internal/", bytes.NewBuffer(req.Data))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// set the peer and topic we are requesting
|
||||
httpReq.Header.Set("REQRESP-PEER-ID", pid.String())
|
||||
httpReq.Header.Set("REQRESP-TOPIC", req.Topic)
|
||||
// for now this can't actually error. in the future, it can due to a network error
|
||||
resp, err := httpreqresp.Do(s.sentinel.ReqRespHandler(), httpReq)
|
||||
if err != nil {
|
||||
// we remove, but dont ban the peer if we fail. this is because its probably not their fault, but maybe it is.
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
// some standard http error code parsing
|
||||
if resp.StatusCode < 200 || resp.StatusCode > 399 {
|
||||
errBody, _ := io.ReadAll(resp.Body)
|
||||
errorMessage := fmt.Errorf("SentinelHttp: %s", string(errBody))
|
||||
if resp.StatusCode >= 400 && resp.StatusCode < 500 {
|
||||
s.sentinel.Peers().RemovePeer(pid)
|
||||
s.sentinel.Host().Peerstore().RemovePeer(pid)
|
||||
s.sentinel.Host().Network().ClosePeer(pid)
|
||||
}
|
||||
if resp.StatusCode >= 500 && resp.StatusCode < 600 {
|
||||
s.sentinel.Host().Peerstore().RemovePeer(pid)
|
||||
s.sentinel.Host().Network().ClosePeer(pid)
|
||||
}
|
||||
return nil, errorMessage
|
||||
}
|
||||
// we should never get an invalid response to this. our responder should always set it on non-error response
|
||||
isError, err := strconv.Atoi(resp.Header.Get("REQRESP-RESPONSE-CODE"))
|
||||
if err != nil {
|
||||
// TODO: think about how to properly handle this. should we? (or should we just assume no response is success?)
|
||||
return nil, err
|
||||
}
|
||||
// known error codes, just remove the peer
|
||||
if isError == 3 || isError == 2 {
|
||||
s.sentinel.Host().Peerstore().RemovePeer(pid)
|
||||
s.sentinel.Host().Network().ClosePeer(pid)
|
||||
return nil, fmt.Errorf("peer error code: %d", isError)
|
||||
}
|
||||
// unknown error codes
|
||||
if isError > 3 {
|
||||
s.logger.Debug("peer returned unknown erro", "id", pid.String())
|
||||
s.sentinel.Host().Peerstore().RemovePeer(pid)
|
||||
s.sentinel.Host().Network().ClosePeer(pid)
|
||||
return nil, fmt.Errorf("peer returned unknown error: %d", isError)
|
||||
}
|
||||
// read the body from the response
|
||||
data, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ans := &sentinelrpc.ResponseData{
|
||||
Data: data,
|
||||
Error: isError != 0,
|
||||
Peer: &sentinelrpc.Peer{
|
||||
Pid: pid.String(),
|
||||
},
|
||||
}
|
||||
return ans, nil
|
||||
|
||||
}
|
||||
|
||||
func (s *SentinelServer) SendRequest(ctx context.Context, req *sentinelrpc.RequestData) (*sentinelrpc.ResponseData, error) {
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
retryReqInterval := time.NewTicker(100 * time.Millisecond)
|
||||
defer retryReqInterval.Stop()
|
||||
doneCh := make(chan *sentinelrpc.ResponseData)
|
||||
// Try finding the data to our peers
|
||||
uniquePeers := map[peer.ID]struct{}{}
|
||||
requestPeer := func(peer *peers.Peer) {
|
||||
peer.MarkUsed()
|
||||
defer peer.MarkUnused()
|
||||
data, isError, err := communication.SendRequestRawToPeer(ctx, s.sentinel.Host(), req.Data, req.Topic, peer.ID())
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "protocols not supported") {
|
||||
peer.Ban("peer does not support protocol")
|
||||
}
|
||||
return
|
||||
}
|
||||
if isError > 3 {
|
||||
peer.Disconnect(fmt.Sprintf("invalid response, starting byte %d", isError))
|
||||
}
|
||||
if isError != 0 {
|
||||
peer.Penalize()
|
||||
return
|
||||
}
|
||||
ans := &sentinelrpc.ResponseData{
|
||||
Data: data,
|
||||
Error: isError != 0,
|
||||
Peer: &sentinelrpc.Peer{
|
||||
Pid: peer.ID().String(),
|
||||
},
|
||||
}
|
||||
select {
|
||||
case doneCh <- ans:
|
||||
peer.MarkReplied()
|
||||
retryReqInterval.Stop()
|
||||
return
|
||||
case <-ctx.Done():
|
||||
return
|
||||
}
|
||||
}
|
||||
doneCh := make(chan *sentinelrpc.ResponseData)
|
||||
go func() {
|
||||
for {
|
||||
pid, err := s.sentinel.RandomPeer(req.Topic)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if _, ok := uniquePeers[pid]; !ok {
|
||||
go s.sentinel.Peers().WithPeer(pid, requestPeer)
|
||||
for i := 0; i < peers.MaxBadResponses; i++ {
|
||||
// this is using return statements instead of continue, since it saves a few lines
|
||||
// but me writing this comment has put them back.. oh no!!! anyways, returning true means we stop.
|
||||
if func() bool {
|
||||
peer, done, err := s.sentinel.Peers().Request()
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
defer done()
|
||||
pid := peer.Id()
|
||||
_, ok := uniquePeers[pid]
|
||||
if ok {
|
||||
return false
|
||||
}
|
||||
resp, err := s.requestPeer(ctx, pid, req)
|
||||
if err != nil {
|
||||
s.logger.Debug("[sentinel] peer gave us bad data", "peer", pid, "err", err)
|
||||
// we simply retry
|
||||
return false
|
||||
}
|
||||
uniquePeers[pid] = struct{}{}
|
||||
}
|
||||
select {
|
||||
case <-retryReqInterval.C:
|
||||
case <-ctx.Done():
|
||||
return
|
||||
doneCh <- resp
|
||||
return true
|
||||
}() {
|
||||
break
|
||||
}
|
||||
}
|
||||
}()
|
||||
@ -217,8 +258,6 @@ func (s *SentinelServer) SendRequest(ctx context.Context, req *sentinelrpc.Reque
|
||||
}
|
||||
|
||||
func (s *SentinelServer) SetStatus(_ context.Context, req *sentinelrpc.Status) (*sentinelrpc.EmptyMessage, error) {
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
// Send the request and get the data if we get an answer.
|
||||
s.sentinel.SetStatus(&cltypes.Status{
|
||||
ForkDigest: utils.Uint32ToBytes4(req.ForkDigest),
|
||||
@ -231,8 +270,6 @@ func (s *SentinelServer) SetStatus(_ context.Context, req *sentinelrpc.Status) (
|
||||
}
|
||||
|
||||
func (s *SentinelServer) GetPeers(_ context.Context, _ *sentinelrpc.EmptyMessage) (*sentinelrpc.PeerCount, error) {
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
// Send the request and get the data if we get an answer.
|
||||
return &sentinelrpc.PeerCount{
|
||||
Amount: uint64(s.sentinel.GetPeersCount()),
|
@ -4,11 +4,12 @@ import (
|
||||
"context"
|
||||
"net"
|
||||
|
||||
"github.com/ledgerwatch/erigon/cl/sentinel"
|
||||
|
||||
"github.com/ledgerwatch/erigon-lib/direct"
|
||||
sentinelrpc "github.com/ledgerwatch/erigon-lib/gointerfaces/sentinel"
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
"github.com/ledgerwatch/erigon/cl/persistence"
|
||||
"github.com/ledgerwatch/erigon/cmd/sentinel/sentinel"
|
||||
"github.com/ledgerwatch/log/v3"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials"
|
@ -1,29 +1,24 @@
|
||||
/*
|
||||
Copyright 2022 Erigon-Lightclient contributors
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
// Copyright 2022 Erigon-Lightclient contributors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// package sentinel
|
||||
package sentinel
|
||||
|
||||
import (
|
||||
"crypto/ecdsa"
|
||||
"crypto/rand"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"net"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/btcsuite/btcd/btcec/v2"
|
||||
"github.com/ledgerwatch/erigon/cmd/sentinel/sentinel/peers"
|
||||
"github.com/ledgerwatch/erigon/p2p/enode"
|
||||
"github.com/ledgerwatch/log/v3"
|
||||
"github.com/libp2p/go-libp2p/core/crypto"
|
||||
@ -107,65 +102,6 @@ func convertToMultiAddr(nodes []*enode.Node) []multiaddr.Multiaddr {
|
||||
|
||||
var shuffleSource = randutil.NewMathRandomGenerator()
|
||||
|
||||
// will iterate onto randoms nodes until our sentinel connects to one
|
||||
func connectToRandomPeer(s *Sentinel, topic string) (peerInfo peer.ID, err error) {
|
||||
var sub *GossipSubscription
|
||||
for t, currSub := range s.subManager.subscriptions {
|
||||
if strings.Contains(t, topic) {
|
||||
sub = currSub
|
||||
}
|
||||
}
|
||||
|
||||
if sub == nil {
|
||||
return peer.ID(""), fmt.Errorf("no peers")
|
||||
}
|
||||
validPeerList := s.Host().Network().Peers()
|
||||
// blocksSub := s.subManager.GetMatchingSubscription(string(BeaconBlockTopic))
|
||||
// if blocksSub != nil {
|
||||
// validPeerList = blocksSub.topic.ListPeers()
|
||||
// }
|
||||
|
||||
//validPeerList := sub.topic.ListPeers()
|
||||
if len(validPeerList) == 0 {
|
||||
return peer.ID(""), fmt.Errorf("no peers")
|
||||
}
|
||||
for i := range validPeerList {
|
||||
j := shuffleSource.Intn(i + 1)
|
||||
validPeerList[i], validPeerList[j] = validPeerList[j], validPeerList[i]
|
||||
}
|
||||
|
||||
connectedPeer := false
|
||||
maxTries := peers.DefaultMaxPeers
|
||||
tries := 0
|
||||
for !connectedPeer {
|
||||
if tries >= maxTries {
|
||||
break
|
||||
}
|
||||
tries++
|
||||
index := int64(0)
|
||||
if len(validPeerList) > 1 {
|
||||
n, err := rand.Int(rand.Reader, big.NewInt(int64(len(validPeerList)-1)))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
index = n.Int64()
|
||||
}
|
||||
available := false
|
||||
s.peers.TryPeer(validPeerList[index], func(peer *peers.Peer, ok bool) {
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
available = peer.IsAvailable()
|
||||
})
|
||||
if !available {
|
||||
continue
|
||||
}
|
||||
return validPeerList[index], nil
|
||||
}
|
||||
|
||||
return peer.ID(""), fmt.Errorf("failed to connect to peer")
|
||||
}
|
||||
|
||||
func (s *Sentinel) oneSlotDuration() time.Duration {
|
||||
return time.Duration(s.cfg.BeaconConfig.SecondsPerSlot) * time.Second
|
||||
}
|
@ -4,9 +4,6 @@ import (
|
||||
"encoding/hex"
|
||||
"testing"
|
||||
|
||||
"github.com/ledgerwatch/erigon/p2p/enode"
|
||||
"github.com/ledgerwatch/erigon/p2p/enr"
|
||||
"github.com/ledgerwatch/erigon/rlp"
|
||||
"github.com/libp2p/go-libp2p/core/peer"
|
||||
)
|
||||
|
||||
@ -63,32 +60,33 @@ func TestMultiAddressBuilderWithID(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestConvertToMultiAddr(t *testing.T) {
|
||||
var r enr.Record
|
||||
if err := rlp.DecodeBytes(pyRecord, &r); err != nil {
|
||||
t.Fatalf("can't decode: %v", err)
|
||||
}
|
||||
n, err := enode.New(enode.ValidSchemes, &r)
|
||||
if err != nil {
|
||||
t.Fatalf("cannot create new node: %v", err)
|
||||
}
|
||||
|
||||
testCases := []struct {
|
||||
nodes []*enode.Node
|
||||
expected []string
|
||||
}{
|
||||
{
|
||||
nodes: []*enode.Node{n},
|
||||
expected: []string{"/ip4/127.0.0.1/tcp/0/p2p/16Uiu2HAmSH2XVgZqYHWucap5kuPzLnt2TsNQkoppVxB5eJGvaXwm"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
multiAddrs := convertToMultiAddr(testCase.nodes)
|
||||
for i, multiAddr := range multiAddrs {
|
||||
if multiAddr.String() != testCase.expected[i] {
|
||||
t.Errorf("for test case: %d, expected: %s, got: %s", i, testCase.expected[i], multiAddr)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// TODO: reimplement this test with the new erigon-lib rlp decoder at some point
|
||||
//func TestConvertToMultiAddr(t *testing.T) {
|
||||
// var r enr.Record
|
||||
// if err := rlp.DecodeBytes(pyRecord, &r); err != nil {
|
||||
// t.Fatalf("can't decode: %v", err)
|
||||
// }
|
||||
// n, err := enode.New(enode.ValidSchemes, &r)
|
||||
// if err != nil {
|
||||
// t.Fatalf("cannot create new node: %v", err)
|
||||
// }
|
||||
//
|
||||
// testCases := []struct {
|
||||
// nodes []*enode.Node
|
||||
// expected []string
|
||||
// }{
|
||||
// {
|
||||
// nodes: []*enode.Node{n},
|
||||
// expected: []string{"/ip4/127.0.0.1/tcp/0/p2p/16Uiu2HAmSH2XVgZqYHWucap5kuPzLnt2TsNQkoppVxB5eJGvaXwm"},
|
||||
// },
|
||||
// }
|
||||
//
|
||||
// for _, testCase := range testCases {
|
||||
// multiAddrs := convertToMultiAddr(testCase.nodes)
|
||||
// for i, multiAddr := range multiAddrs {
|
||||
// if multiAddr.String() != testCase.expected[i] {
|
||||
// t.Errorf("for test case: %d, expected: %s, got: %s", i, testCase.expected[i], multiAddr)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
@ -1,10 +1,9 @@
|
||||
package consensus_tests
|
||||
|
||||
import (
|
||||
"github.com/ledgerwatch/erigon/spectest"
|
||||
"io/fs"
|
||||
"testing"
|
||||
|
||||
"github.com/ledgerwatch/erigon/spectest"
|
||||
)
|
||||
|
||||
type BlsAggregateVerify struct {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package consensus_tests
|
||||
|
||||
import (
|
||||
"github.com/ledgerwatch/erigon/spectest"
|
||||
"io/fs"
|
||||
"os"
|
||||
"testing"
|
||||
@ -9,7 +10,6 @@ import (
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/core/state"
|
||||
"github.com/ledgerwatch/erigon/cl/transition/impl/eth2/statechange"
|
||||
|
||||
"github.com/ledgerwatch/erigon/spectest"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
@ -3,10 +3,10 @@ package consensus_tests
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/ledgerwatch/erigon/cl/transition/machine"
|
||||
"github.com/ledgerwatch/erigon/spectest"
|
||||
"io/fs"
|
||||
"testing"
|
||||
|
||||
"github.com/ledgerwatch/erigon/spectest"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
@ -3,6 +3,7 @@ package consensus_tests
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/ledgerwatch/erigon/spectest"
|
||||
"io/fs"
|
||||
"testing"
|
||||
|
||||
@ -16,7 +17,6 @@ import (
|
||||
|
||||
"github.com/ledgerwatch/erigon-lib/common"
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
"github.com/ledgerwatch/erigon/spectest"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
@ -2,12 +2,12 @@ package consensus_tests
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/ledgerwatch/erigon/spectest"
|
||||
"io/fs"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/ledgerwatch/erigon/cl/clparams"
|
||||
"github.com/ledgerwatch/erigon/spectest"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
@ -2,6 +2,7 @@ package consensus_tests
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/ledgerwatch/erigon/spectest"
|
||||
"io/fs"
|
||||
"os"
|
||||
"testing"
|
||||
@ -10,7 +11,6 @@ import (
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes/solid"
|
||||
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
"github.com/ledgerwatch/erigon/spectest"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
@ -1,10 +1,9 @@
|
||||
package consensus_tests
|
||||
|
||||
import (
|
||||
"github.com/ledgerwatch/erigon/spectest"
|
||||
"io/fs"
|
||||
"testing"
|
||||
|
||||
"github.com/ledgerwatch/erigon/spectest"
|
||||
)
|
||||
|
||||
type RewardsCore struct {
|
||||
|
@ -2,12 +2,12 @@ package consensus_tests
|
||||
|
||||
import (
|
||||
"github.com/ledgerwatch/erigon/cl/transition/machine"
|
||||
"github.com/ledgerwatch/erigon/spectest"
|
||||
"io/fs"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
"github.com/ledgerwatch/erigon/spectest"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
@ -1,6 +1,7 @@
|
||||
package consensus_tests
|
||||
|
||||
import (
|
||||
"github.com/ledgerwatch/erigon/spectest"
|
||||
"io/fs"
|
||||
"testing"
|
||||
|
||||
@ -10,7 +11,6 @@ import (
|
||||
|
||||
"github.com/ledgerwatch/erigon-lib/common"
|
||||
"github.com/ledgerwatch/erigon/cl/utils"
|
||||
"github.com/ledgerwatch/erigon/spectest"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
@ -1,6 +1,7 @@
|
||||
package consensus_tests
|
||||
|
||||
import (
|
||||
"github.com/ledgerwatch/erigon/spectest"
|
||||
"io/fs"
|
||||
"testing"
|
||||
|
||||
@ -11,7 +12,6 @@ import (
|
||||
"github.com/ledgerwatch/erigon-lib/types/ssz"
|
||||
|
||||
"github.com/ledgerwatch/erigon/cl/utils"
|
||||
"github.com/ledgerwatch/erigon/spectest"
|
||||
"github.com/stretchr/testify/require"
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
@ -3,12 +3,12 @@ package consensus_tests
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/ledgerwatch/erigon/cl/transition/machine"
|
||||
"github.com/ledgerwatch/erigon/spectest"
|
||||
"io/fs"
|
||||
"testing"
|
||||
|
||||
"github.com/ledgerwatch/erigon/cl/clparams"
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
"github.com/ledgerwatch/erigon/spectest"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
@ -4,11 +4,11 @@ import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/ledgerwatch/erigon/spectest"
|
||||
|
||||
"github.com/ledgerwatch/erigon/cl/transition"
|
||||
|
||||
"github.com/ledgerwatch/erigon/cl/spectest/consensus_tests"
|
||||
|
||||
"github.com/ledgerwatch/erigon/spectest"
|
||||
)
|
||||
|
||||
func Test(t *testing.T) {
|
||||
|
@ -7,8 +7,8 @@ import (
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
"github.com/ledgerwatch/erigon-lib/metrics"
|
||||
"github.com/ledgerwatch/erigon/cl/abstract"
|
||||
"github.com/ledgerwatch/erigon/metrics"
|
||||
|
||||
"github.com/ledgerwatch/erigon/cl/transition/impl/eth2/statechange"
|
||||
"golang.org/x/exp/slices"
|
||||
|
@ -2,13 +2,13 @@ package statechange_test
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"github.com/ledgerwatch/erigon-lib/common"
|
||||
"github.com/ledgerwatch/erigon/cl/transition/impl/eth2/statechange"
|
||||
"testing"
|
||||
|
||||
"github.com/ledgerwatch/erigon/cl/clparams"
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes/solid"
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/core/state"
|
||||
"github.com/ledgerwatch/erigon/common"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
|
@ -4,8 +4,8 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/ledgerwatch/erigon-lib/metrics"
|
||||
"github.com/ledgerwatch/erigon/cl/abstract"
|
||||
"github.com/ledgerwatch/erigon/metrics"
|
||||
|
||||
"github.com/ledgerwatch/erigon/cl/clparams"
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
|
@ -1,11 +1,11 @@
|
||||
package utils_test
|
||||
|
||||
import (
|
||||
"github.com/ledgerwatch/erigon-lib/common"
|
||||
"testing"
|
||||
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
"github.com/ledgerwatch/erigon/cl/utils"
|
||||
"github.com/ledgerwatch/erigon/common"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
|
@ -7,12 +7,12 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/jedib0t/go-pretty/v6/progress"
|
||||
"github.com/ledgerwatch/erigon-lib/gointerfaces/sentinel"
|
||||
"github.com/ledgerwatch/erigon-lib/kv/mdbx"
|
||||
"github.com/ledgerwatch/erigon/cl/abstract"
|
||||
"github.com/ledgerwatch/erigon/cl/clparams"
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
persistence2 "github.com/ledgerwatch/erigon/cl/persistence"
|
||||
|
||||
"github.com/ledgerwatch/erigon-lib/kv/mdbx"
|
||||
"github.com/ledgerwatch/erigon/cl/persistence"
|
||||
"github.com/ledgerwatch/erigon/cl/persistence/db_config"
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/core"
|
||||
@ -24,6 +24,9 @@ import (
|
||||
"github.com/ledgerwatch/erigon/cl/transition/impl/eth2"
|
||||
"github.com/ledgerwatch/erigon/cl/transition/machine"
|
||||
"github.com/ledgerwatch/erigon/cl/utils"
|
||||
|
||||
"github.com/jedib0t/go-pretty/v6/progress"
|
||||
"github.com/ledgerwatch/erigon-lib/gointerfaces/sentinel"
|
||||
"github.com/ledgerwatch/log/v3"
|
||||
"github.com/spf13/afero"
|
||||
"golang.org/x/sync/errgroup"
|
||||
@ -121,9 +124,9 @@ func (b *Blocks) Run(ctx *Context) error {
|
||||
return err
|
||||
}
|
||||
defer tx.Rollback()
|
||||
beaconDB := persistence.NewBeaconChainDatabaseFilesystem(persistence.NewAferoRawBlockSaver(aferoFS, beaconConfig), nil, beaconConfig)
|
||||
beaconDB := persistence2.NewBeaconChainDatabaseFilesystem(persistence2.NewAferoRawBlockSaver(aferoFS, beaconConfig), nil, beaconConfig)
|
||||
for _, vv := range resp {
|
||||
err := beaconDB.WriteBlock(tx, ctx, vv, true)
|
||||
err := beaconDB.WriteBlock(ctx, tx, vv, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -161,7 +164,7 @@ func (b *Epochs) Run(cctx *Context) error {
|
||||
beaconDB := persistence.NewBeaconChainDatabaseFilesystem(persistence.NewAferoRawBlockSaver(aferoFS, beaconConfig), nil, beaconConfig)
|
||||
|
||||
beacon := rpc.NewBeaconRpcP2P(ctx, s, beaconConfig, genesisConfig)
|
||||
rpcSource := persistence.NewBeaconRpcSource(beacon)
|
||||
rpcSource := persistence2.NewBeaconRpcSource(beacon)
|
||||
|
||||
err = beacon.SetStatus(
|
||||
genesisConfig.GenesisValidatorRoot,
|
||||
@ -227,7 +230,7 @@ func (b *Epochs) Run(cctx *Context) error {
|
||||
egg.Go(func() error {
|
||||
var blocks []*peers.PeeredObject[*cltypes.SignedBeaconBlock]
|
||||
for {
|
||||
blocks, err = rpcSource.GetRange(tx, ctx, uint64(ii)*beaconConfig.SlotsPerEpoch, beaconConfig.SlotsPerEpoch)
|
||||
blocks, err = rpcSource.GetRange(ctx, tx, uint64(ii)*beaconConfig.SlotsPerEpoch, beaconConfig.SlotsPerEpoch)
|
||||
if err != nil {
|
||||
log.Error("dl error", "err", err, "epoch", ii)
|
||||
} else {
|
||||
@ -237,7 +240,7 @@ func (b *Epochs) Run(cctx *Context) error {
|
||||
for _, v := range blocks {
|
||||
tk.Increment(1)
|
||||
_, _ = beaconDB, v
|
||||
err := beaconDB.WriteBlock(tx, ctx, v.Data, true)
|
||||
err := beaconDB.WriteBlock(ctx, tx, v.Data, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -2,12 +2,12 @@ package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
|
||||
"github.com/ledgerwatch/erigon/metrics"
|
||||
"github.com/ledgerwatch/erigon/turbo/debug"
|
||||
|
||||
"github.com/ledgerwatch/erigon-lib/metrics"
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/forkchoice"
|
||||
|
||||
"github.com/ledgerwatch/erigon/turbo/debug"
|
||||
|
||||
"github.com/ledgerwatch/erigon/cmd/caplin-regression/regression"
|
||||
"github.com/ledgerwatch/log/v3"
|
||||
"golang.org/x/exp/slices"
|
||||
|
@ -1,16 +1,15 @@
|
||||
package regression
|
||||
|
||||
import (
|
||||
clparams2 "github.com/ledgerwatch/erigon/cl/clparams"
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/core/state"
|
||||
"github.com/ledgerwatch/erigon/cl/utils"
|
||||
"io/fs"
|
||||
"io/ioutil"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
|
||||
"github.com/ledgerwatch/erigon/cl/clparams"
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/core/state"
|
||||
"github.com/ledgerwatch/erigon/cl/utils"
|
||||
)
|
||||
|
||||
func (r *RegressionTester) readStartingState() (*state.CachingBeaconState, error) {
|
||||
@ -18,8 +17,8 @@ func (r *RegressionTester) readStartingState() (*state.CachingBeaconState, error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s := state.New(&clparams.MainnetBeaconConfig)
|
||||
if err := utils.DecodeSSZSnappy(s, stateFile, int(clparams.CapellaVersion)); err != nil {
|
||||
s := state.New(&clparams2.MainnetBeaconConfig)
|
||||
if err := utils.DecodeSSZSnappy(s, stateFile, int(clparams2.CapellaVersion)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return s, nil
|
||||
@ -39,7 +38,7 @@ func (r *RegressionTester) initBlocks() error {
|
||||
return err
|
||||
}
|
||||
b := new(cltypes.SignedBeaconBlock)
|
||||
if err := utils.DecodeSSZSnappy(b, f, int(clparams.CapellaVersion)); err != nil {
|
||||
if err := utils.DecodeSSZSnappy(b, f, int(clparams2.CapellaVersion)); err != nil {
|
||||
return err
|
||||
}
|
||||
r.blockList = append(r.blockList, b)
|
||||
|
@ -5,15 +5,16 @@ import (
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
"github.com/ledgerwatch/erigon/cl/clparams"
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
solid2 "github.com/ledgerwatch/erigon/cl/cltypes/solid"
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/forkchoice"
|
||||
"github.com/ledgerwatch/erigon/cl/pool"
|
||||
|
||||
"github.com/Giulio2002/bls"
|
||||
"github.com/ledgerwatch/erigon-lib/common"
|
||||
"github.com/ledgerwatch/erigon-lib/common/dbg"
|
||||
"github.com/ledgerwatch/erigon/cl/clparams"
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes/solid"
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/forkchoice"
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/forkchoice/fork_graph"
|
||||
"github.com/ledgerwatch/erigon/cl/pool"
|
||||
"github.com/ledgerwatch/log/v3"
|
||||
"github.com/spf13/afero"
|
||||
)
|
||||
@ -49,7 +50,7 @@ func (r *RegressionTester) Run(name string, fn func(*forkchoice.ForkChoiceStore,
|
||||
}
|
||||
log.Info("Loading public keys into memory")
|
||||
bls.SetEnabledCaching(true)
|
||||
state.ForEachValidator(func(v solid.Validator, idx, total int) bool {
|
||||
state.ForEachValidator(func(v solid2.Validator, idx, total int) bool {
|
||||
pk := v.PublicKey()
|
||||
if err := bls.LoadPublicKeyIntoCache(pk[:], false); err != nil {
|
||||
panic(err)
|
||||
@ -86,7 +87,7 @@ func TestRegressionWithValidation(store *forkchoice.ForkChoiceStore, block *clty
|
||||
if err := store.OnBlock(block, false, true); err != nil {
|
||||
return err
|
||||
}
|
||||
block.Block.Body.Attestations.Range(func(index int, value *solid.Attestation, length int) bool {
|
||||
block.Block.Body.Attestations.Range(func(index int, value *solid2.Attestation, length int) bool {
|
||||
store.OnAttestation(value, true)
|
||||
return true
|
||||
})
|
||||
|
@ -10,7 +10,9 @@ import (
|
||||
"github.com/ledgerwatch/erigon/cl/beacon/handler"
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes/solid"
|
||||
"github.com/ledgerwatch/erigon/cl/freezer"
|
||||
freezer2 "github.com/ledgerwatch/erigon/cl/freezer"
|
||||
"github.com/ledgerwatch/erigon/cl/persistence"
|
||||
persistence2 "github.com/ledgerwatch/erigon/cl/persistence"
|
||||
"github.com/ledgerwatch/erigon/cl/persistence/db_config"
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/core/state"
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/execution_client"
|
||||
@ -19,6 +21,7 @@ import (
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/network"
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/stages"
|
||||
"github.com/ledgerwatch/erigon/cl/pool"
|
||||
"github.com/ledgerwatch/erigon/cl/rpc"
|
||||
"github.com/spf13/afero"
|
||||
|
||||
"github.com/Giulio2002/bls"
|
||||
@ -27,14 +30,13 @@ import (
|
||||
"github.com/ledgerwatch/erigon-lib/kv"
|
||||
"github.com/ledgerwatch/erigon-lib/kv/mdbx"
|
||||
"github.com/ledgerwatch/erigon/cl/clparams"
|
||||
"github.com/ledgerwatch/erigon/cl/rpc"
|
||||
"github.com/ledgerwatch/log/v3"
|
||||
)
|
||||
|
||||
func OpenCaplinDatabase(ctx context.Context,
|
||||
databaseConfig db_config.DatabaseConfiguration,
|
||||
beaconConfig *clparams.BeaconChainConfig,
|
||||
rawBeaconChain persistence.RawBeaconBlockChain,
|
||||
rawBeaconChain persistence2.RawBeaconBlockChain,
|
||||
dbPath string,
|
||||
engine execution_client.ExecutionEngine,
|
||||
wipeout bool,
|
||||
@ -67,7 +69,7 @@ func OpenCaplinDatabase(ctx context.Context,
|
||||
db.Close() // close sql database here
|
||||
}()
|
||||
}
|
||||
return persistence.NewBeaconChainDatabaseFilesystem(rawBeaconChain, engine, beaconConfig), db, nil
|
||||
return persistence2.NewBeaconChainDatabaseFilesystem(rawBeaconChain, engine, beaconConfig), db, nil
|
||||
}
|
||||
|
||||
func RunCaplinPhase1(ctx context.Context, sentinel sentinel.SentinelClient, engine execution_client.ExecutionEngine,
|
||||
@ -86,7 +88,7 @@ func RunCaplinPhase1(ctx context.Context, sentinel sentinel.SentinelClient, engi
|
||||
logger := log.New("app", "caplin")
|
||||
|
||||
if caplinFreezer != nil {
|
||||
if err := freezer.PutObjectSSZIntoFreezer("beaconState", "caplin_core", 0, state, caplinFreezer); err != nil {
|
||||
if err := freezer2.PutObjectSSZIntoFreezer("beaconState", "caplin_core", 0, state, caplinFreezer); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -19,21 +19,21 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/ledgerwatch/erigon/cl/beacon"
|
||||
"github.com/ledgerwatch/erigon/cl/freezer"
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
"github.com/ledgerwatch/erigon/cl/fork"
|
||||
freezer2 "github.com/ledgerwatch/erigon/cl/freezer"
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/core"
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/core/state"
|
||||
"github.com/ledgerwatch/erigon/cl/phase1/execution_client"
|
||||
execution_client2 "github.com/ledgerwatch/erigon/cl/phase1/execution_client"
|
||||
"github.com/ledgerwatch/erigon/cl/sentinel"
|
||||
"github.com/ledgerwatch/erigon/cl/sentinel/service"
|
||||
|
||||
"github.com/ledgerwatch/log/v3"
|
||||
"github.com/urfave/cli/v2"
|
||||
|
||||
"github.com/ledgerwatch/erigon/cl/cltypes"
|
||||
"github.com/ledgerwatch/erigon/cl/fork"
|
||||
"github.com/ledgerwatch/erigon/cmd/caplin/caplin1"
|
||||
lcCli "github.com/ledgerwatch/erigon/cmd/sentinel/cli"
|
||||
"github.com/ledgerwatch/erigon/cmd/sentinel/cli/flags"
|
||||
"github.com/ledgerwatch/erigon/cmd/sentinel/sentinel"
|
||||
"github.com/ledgerwatch/erigon/cmd/sentinel/sentinel/service"
|
||||
app "github.com/ledgerwatch/erigon/turbo/app"
|
||||
"github.com/ledgerwatch/erigon/turbo/debug"
|
||||
)
|
||||
@ -104,9 +104,9 @@ func runCaplinNode(cliCtx *cli.Context) error {
|
||||
log.Error("[Checkpoint Sync] Failed", "reason", err)
|
||||
return err
|
||||
}
|
||||
var executionEngine execution_client.ExecutionEngine
|
||||
var executionEngine execution_client2.ExecutionEngine
|
||||
if cfg.RunEngineAPI {
|
||||
cc, err := execution_client.NewExecutionClientRPC(ctx, cfg.JwtSecret, cfg.EngineAPIAddr, cfg.EngineAPIPort)
|
||||
cc, err := execution_client2.NewExecutionClientRPC(ctx, cfg.JwtSecret, cfg.EngineAPIAddr, cfg.EngineAPIPort)
|
||||
if err != nil {
|
||||
log.Error("could not start engine api", "err", err)
|
||||
}
|
||||
@ -114,9 +114,9 @@ func runCaplinNode(cliCtx *cli.Context) error {
|
||||
executionEngine = cc
|
||||
}
|
||||
|
||||
var caplinFreezer freezer.Freezer
|
||||
var caplinFreezer freezer2.Freezer
|
||||
if cfg.RecordMode {
|
||||
caplinFreezer = &freezer.RootPathOsFs{
|
||||
caplinFreezer = &freezer2.RootPathOsFs{
|
||||
Root: cfg.RecordDir,
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package contracts
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/ledgerwatch/erigon-lib/common/hexutil"
|
||||
"math/big"
|
||||
|
||||
ethereum "github.com/ledgerwatch/erigon"
|
||||
@ -10,7 +11,6 @@ import (
|
||||
"github.com/ledgerwatch/erigon-lib/common/hexutility"
|
||||
"github.com/ledgerwatch/erigon/accounts/abi/bind"
|
||||
"github.com/ledgerwatch/erigon/cmd/devnet/devnet"
|
||||
"github.com/ledgerwatch/erigon/common/hexutil"
|
||||
"github.com/ledgerwatch/erigon/core/types"
|
||||
"github.com/ledgerwatch/erigon/rpc"
|
||||
"github.com/ledgerwatch/erigon/turbo/adapter/ethapi"
|
||||
|
@ -3,6 +3,7 @@ package contracts_steps
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/ledgerwatch/erigon-lib/common/hexutil"
|
||||
"math/big"
|
||||
|
||||
ethereum "github.com/ledgerwatch/erigon"
|
||||
@ -18,7 +19,6 @@ import (
|
||||
"github.com/ledgerwatch/erigon/cmd/devnet/requests"
|
||||
"github.com/ledgerwatch/erigon/cmd/devnet/scenarios"
|
||||
"github.com/ledgerwatch/erigon/cmd/devnet/transactions"
|
||||
"github.com/ledgerwatch/erigon/common/hexutil"
|
||||
"github.com/ledgerwatch/erigon/core/types"
|
||||
"github.com/ledgerwatch/erigon/rpc"
|
||||
)
|
||||
|
@ -2,11 +2,11 @@ package requests
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/ledgerwatch/erigon-lib/common/hexutil"
|
||||
"math/big"
|
||||
|
||||
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
||||
"github.com/ledgerwatch/erigon-lib/common/hexutility"
|
||||
"github.com/ledgerwatch/erigon/common/hexutil"
|
||||
"github.com/ledgerwatch/erigon/rpc"
|
||||
)
|
||||
|
||||
|
@ -2,11 +2,11 @@ package requests
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
hexutil2 "github.com/ledgerwatch/erigon-lib/common/hexutil"
|
||||
"math/big"
|
||||
|
||||
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
||||
|
||||
"github.com/ledgerwatch/erigon/common/hexutil"
|
||||
"github.com/ledgerwatch/erigon/common/math"
|
||||
"github.com/ledgerwatch/erigon/core/types"
|
||||
"github.com/ledgerwatch/erigon/rpc"
|
||||
@ -24,7 +24,7 @@ func (bn BlockNumber) Uint64() uint64 {
|
||||
}
|
||||
|
||||
func AsBlockNumber(n *big.Int) BlockNumber {
|
||||
return BlockNumber(hexutil.EncodeBig(n))
|
||||
return BlockNumber(hexutil2.EncodeBig(n))
|
||||
}
|
||||
|
||||
var BlockNumbers = struct {
|
||||
@ -72,11 +72,11 @@ func (b *Block) UnmarshalJSON(input []byte) error {
|
||||
|
||||
type EthGetTransactionCount struct {
|
||||
CommonResponse
|
||||
Result hexutil.Uint64 `json:"result"`
|
||||
Result hexutil2.Uint64 `json:"result"`
|
||||
}
|
||||
|
||||
func (reqGen *requestGenerator) BlockNumber() (uint64, error) {
|
||||
var result hexutil.Uint64
|
||||
var result hexutil2.Uint64
|
||||
|
||||
if err := reqGen.callCli(&result, Methods.ETHBlockNumber); err != nil {
|
||||
return 0, err
|
||||
|
@ -4,11 +4,11 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/ledgerwatch/erigon-lib/common/hexutil"
|
||||
|
||||
ethereum "github.com/ledgerwatch/erigon"
|
||||
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
||||
"github.com/ledgerwatch/erigon-lib/common/hexutility"
|
||||
"github.com/ledgerwatch/erigon/common/hexutil"
|
||||
"github.com/ledgerwatch/erigon/core/types"
|
||||
)
|
||||
|
||||
|
@ -3,10 +3,10 @@ package requests
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/ledgerwatch/erigon-lib/common/hexutil"
|
||||
|
||||
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
||||
"github.com/ledgerwatch/erigon-lib/common/hexutility"
|
||||
"github.com/ledgerwatch/erigon/common/hexutil"
|
||||
"github.com/ledgerwatch/erigon/rpc"
|
||||
"github.com/ledgerwatch/erigon/turbo/adapter/ethapi"
|
||||
)
|
||||
|
@ -4,12 +4,12 @@ import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/ledgerwatch/erigon-lib/common/hexutil"
|
||||
"math/big"
|
||||
|
||||
ethereum "github.com/ledgerwatch/erigon"
|
||||
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
||||
"github.com/ledgerwatch/erigon-lib/common/hexutility"
|
||||
"github.com/ledgerwatch/erigon/common/hexutil"
|
||||
"github.com/ledgerwatch/erigon/core/types"
|
||||
"github.com/ledgerwatch/erigon/rpc"
|
||||
"github.com/ledgerwatch/erigon/turbo/adapter/ethapi"
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/ledgerwatch/erigon/cl/merkle_tree"
|
||||
"math"
|
||||
"math/big"
|
||||
"strings"
|
||||
@ -14,7 +15,6 @@ import (
|
||||
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
||||
"github.com/ledgerwatch/erigon-lib/common/hexutility"
|
||||
"github.com/ledgerwatch/erigon/accounts/abi/bind"
|
||||
"github.com/ledgerwatch/erigon/cl/merkle_tree"
|
||||
"github.com/ledgerwatch/erigon/cmd/devnet/devnet"
|
||||
"github.com/ledgerwatch/erigon/cmd/devnet/requests"
|
||||
"github.com/ledgerwatch/erigon/core/types"
|
||||
|
@ -3,6 +3,7 @@ package transactions
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/ledgerwatch/erigon-lib/common/hexutil"
|
||||
"time"
|
||||
|
||||
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
||||
@ -12,7 +13,6 @@ import (
|
||||
"github.com/ledgerwatch/erigon/cmd/devnet/devnetutils"
|
||||
"github.com/ledgerwatch/erigon/cmd/devnet/requests"
|
||||
"github.com/ledgerwatch/erigon/cmd/devnet/services"
|
||||
"github.com/ledgerwatch/erigon/common/hexutil"
|
||||
"github.com/ledgerwatch/erigon/rpc"
|
||||
)
|
||||
|
||||
|
@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/ledgerwatch/erigon-lib/metrics"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@ -12,7 +13,6 @@ import (
|
||||
"github.com/ledgerwatch/erigon-lib/common/datadir"
|
||||
"github.com/ledgerwatch/erigon-lib/common/dbg"
|
||||
"github.com/ledgerwatch/erigon/diagnostics"
|
||||
"github.com/ledgerwatch/erigon/metrics"
|
||||
"github.com/ledgerwatch/log/v3"
|
||||
"github.com/pelletier/go-toml"
|
||||
"github.com/urfave/cli/v2"
|
||||
|
@ -39,7 +39,6 @@ import (
|
||||
"github.com/ledgerwatch/erigon-lib/common/length"
|
||||
"github.com/ledgerwatch/erigon-lib/kv"
|
||||
"github.com/ledgerwatch/erigon-lib/kv/kvcfg"
|
||||
"github.com/ledgerwatch/erigon/common"
|
||||
"github.com/ledgerwatch/erigon/common/math"
|
||||
"github.com/ledgerwatch/erigon/consensus/ethash"
|
||||
"github.com/ledgerwatch/erigon/consensus/merge"
|
||||
@ -610,8 +609,8 @@ func CalculateStateRoot(tx kv.RwTx) (*libcommon.Hash, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
h := common.NewHasher()
|
||||
defer common.ReturnHasherToPool(h)
|
||||
h := libcommon.NewHasher()
|
||||
defer libcommon.ReturnHasherToPool(h)
|
||||
for k, v, err := c.First(); k != nil; k, v, err = c.Next() {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("interate over plain state: %w", err)
|
||||
@ -634,11 +633,11 @@ func CalculateStateRoot(tx kv.RwTx) (*libcommon.Hash, error) {
|
||||
h.Sha.Write(k[length.Addr+length.Incarnation:])
|
||||
//nolint:errcheck
|
||||
h.Sha.Read(newK[length.Hash+length.Incarnation:])
|
||||
if err = tx.Put(kv.HashedStorage, newK, common.CopyBytes(v)); err != nil {
|
||||
if err = tx.Put(kv.HashedStorage, newK, libcommon.CopyBytes(v)); err != nil {
|
||||
return nil, fmt.Errorf("insert hashed key: %w", err)
|
||||
}
|
||||
} else {
|
||||
if err = tx.Put(kv.HashedAccounts, newK, common.CopyBytes(v)); err != nil {
|
||||
if err = tx.Put(kv.HashedAccounts, newK, libcommon.CopyBytes(v)); err != nil {
|
||||
return nil, fmt.Errorf("insert hashed key: %w", err)
|
||||
}
|
||||
}
|
||||
|
@ -43,7 +43,6 @@ import (
|
||||
|
||||
"github.com/ledgerwatch/erigon/cmd/evm/internal/compiler"
|
||||
"github.com/ledgerwatch/erigon/cmd/utils"
|
||||
"github.com/ledgerwatch/erigon/common"
|
||||
"github.com/ledgerwatch/erigon/core"
|
||||
"github.com/ledgerwatch/erigon/core/state"
|
||||
"github.com/ledgerwatch/erigon/core/vm"
|
||||
@ -217,7 +216,7 @@ func runCmd(ctx *cli.Context) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
code = common.Hex2Bytes(bin)
|
||||
code = libcommon.Hex2Bytes(bin)
|
||||
}
|
||||
initialGas := ctx.Uint64(GasFlag.Name)
|
||||
if genesisConfig.GasLimit != 0 {
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/ledgerwatch/erigon-lib/kv/dbutils"
|
||||
"math/big"
|
||||
"net/http"
|
||||
_ "net/http/pprof" //nolint:gosec
|
||||
@ -38,7 +39,6 @@ import (
|
||||
"github.com/ledgerwatch/erigon/cmd/hack/flow"
|
||||
"github.com/ledgerwatch/erigon/cmd/hack/tool"
|
||||
"github.com/ledgerwatch/erigon/common"
|
||||
"github.com/ledgerwatch/erigon/common/dbutils"
|
||||
"github.com/ledgerwatch/erigon/common/paths"
|
||||
"github.com/ledgerwatch/erigon/core"
|
||||
"github.com/ledgerwatch/erigon/core/rawdb"
|
||||
@ -421,7 +421,7 @@ func iterateOverCode(chaindata string) error {
|
||||
if err := tx.ForEach(kv.Code, nil, func(k, v []byte) error {
|
||||
if len(v) > 0 && v[0] == 0xef {
|
||||
fmt.Printf("Found code with hash %x: %x\n", k, v)
|
||||
hashes[libcommon.BytesToHash(k)] = common.CopyBytes(v)
|
||||
hashes[libcommon.BytesToHash(k)] = libcommon.CopyBytes(v)
|
||||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
|
@ -389,7 +389,7 @@ MainLoop:
|
||||
if !fileScanner.Scan() {
|
||||
break MainLoop
|
||||
}
|
||||
k := common.CopyBytes(fileScanner.Bytes())
|
||||
k := common2.CopyBytes(fileScanner.Bytes())
|
||||
if bytes.Equal(k, endData) {
|
||||
break
|
||||
}
|
||||
@ -397,7 +397,7 @@ MainLoop:
|
||||
if !fileScanner.Scan() {
|
||||
break MainLoop
|
||||
}
|
||||
v := common.CopyBytes(fileScanner.Bytes())
|
||||
v := common2.CopyBytes(fileScanner.Bytes())
|
||||
v = common.FromHex(string(v[1:]))
|
||||
|
||||
if casted, ok := c.(kv.RwCursorDupSort); ok {
|
||||
|
@ -5,13 +5,13 @@ import (
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/ledgerwatch/erigon-lib/metrics"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/holiman/uint256"
|
||||
"github.com/ledgerwatch/erigon/metrics"
|
||||
"github.com/ledgerwatch/log/v3"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/ledgerwatch/erigon-lib/kv/dbutils"
|
||||
"os"
|
||||
"sort"
|
||||
"time"
|
||||
@ -24,7 +25,6 @@ import (
|
||||
|
||||
"github.com/ledgerwatch/erigon/cmd/hack/tool/fromdb"
|
||||
"github.com/ledgerwatch/erigon/cmd/utils"
|
||||
"github.com/ledgerwatch/erigon/common/dbutils"
|
||||
"github.com/ledgerwatch/erigon/common/debugprint"
|
||||
"github.com/ledgerwatch/erigon/core"
|
||||
"github.com/ledgerwatch/erigon/core/state"
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user