diff --git a/gointerfaces/remote/kv.pb.go b/gointerfaces/remote/kv.pb.go index b7f1c3131..b50b2e888 100644 --- a/gointerfaces/remote/kv.pb.go +++ b/gointerfaces/remote/kv.pb.go @@ -508,8 +508,7 @@ type StateChange struct { BlockHash *types.H256 `protobuf:"bytes,3,opt,name=blockHash,proto3" json:"blockHash,omitempty"` Changes []*AccountChange `protobuf:"bytes,4,rep,name=changes,proto3" json:"changes,omitempty"` Txs [][]byte `protobuf:"bytes,5,rep,name=txs,proto3" json:"txs,omitempty"` // enable by withTransactions=true - BlockBaseFee uint64 `protobuf:"varint,6,opt,name=blockBaseFee,proto3" json:"blockBaseFee,omitempty"` // enable by withTransactions=true - ProtocolBaseFee uint64 `protobuf:"varint,7,opt,name=protocolBaseFee,proto3" json:"protocolBaseFee,omitempty"` // enable by withTransactions=true + ProtocolBaseFee uint64 `protobuf:"varint,6,opt,name=protocolBaseFee,proto3" json:"protocolBaseFee,omitempty"` // enable by withTransactions=true } func (x *StateChange) Reset() { @@ -579,13 +578,6 @@ func (x *StateChange) GetTxs() [][]byte { return nil } -func (x *StateChange) GetBlockBaseFee() uint64 { - if x != nil { - return x.BlockBaseFee - } - return 0 -} - func (x *StateChange) GetProtocolBaseFee() uint64 { if x != nil { return x.ProtocolBaseFee @@ -686,7 +678,7 @@ var file_remote_kv_proto_rawDesc = []byte{ 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x73, 0x18, 0x06, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x2e, 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x52, 0x0e, 0x73, 0x74, 0x6f, - 0x72, 0x61, 0x67, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x73, 0x22, 0x9c, 0x02, 0x0a, 0x0b, + 0x72, 0x61, 0x67, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x73, 0x22, 0xf8, 0x01, 0x0a, 0x0b, 0x53, 0x74, 0x61, 0x74, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x12, 0x2f, 0x0a, 0x09, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x11, 0x2e, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x2e, 0x44, 0x69, 0x72, 0x65, 0x63, 0x74, 0x69, 0x6f, @@ -699,52 +691,50 @@ var file_remote_kv_proto_rawDesc = []byte{ 0x6e, 0x67, 0x65, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x2e, 0x41, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x52, 0x07, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x73, 0x12, 0x10, 0x0a, 0x03, 0x74, 0x78, - 0x73, 0x18, 0x05, 0x20, 0x03, 0x28, 0x0c, 0x52, 0x03, 0x74, 0x78, 0x73, 0x12, 0x22, 0x0a, 0x0c, - 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x42, 0x61, 0x73, 0x65, 0x46, 0x65, 0x65, 0x18, 0x06, 0x20, 0x01, - 0x28, 0x04, 0x52, 0x0c, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x42, 0x61, 0x73, 0x65, 0x46, 0x65, 0x65, - 0x12, 0x28, 0x0a, 0x0f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x42, 0x61, 0x73, 0x65, - 0x46, 0x65, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0f, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x63, 0x6f, 0x6c, 0x42, 0x61, 0x73, 0x65, 0x46, 0x65, 0x65, 0x22, 0x62, 0x0a, 0x12, 0x53, 0x74, - 0x61, 0x74, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x12, 0x20, 0x0a, 0x0b, 0x77, 0x69, 0x74, 0x68, 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0b, 0x77, 0x69, 0x74, 0x68, 0x53, 0x74, 0x6f, 0x72, 0x61, - 0x67, 0x65, 0x12, 0x2a, 0x0a, 0x10, 0x77, 0x69, 0x74, 0x68, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, - 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x10, 0x77, 0x69, - 0x74, 0x68, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2a, 0xe8, - 0x01, 0x0a, 0x02, 0x4f, 0x70, 0x12, 0x09, 0x0a, 0x05, 0x46, 0x49, 0x52, 0x53, 0x54, 0x10, 0x00, - 0x12, 0x0d, 0x0a, 0x09, 0x46, 0x49, 0x52, 0x53, 0x54, 0x5f, 0x44, 0x55, 0x50, 0x10, 0x01, 0x12, - 0x08, 0x0a, 0x04, 0x53, 0x45, 0x45, 0x4b, 0x10, 0x02, 0x12, 0x0d, 0x0a, 0x09, 0x53, 0x45, 0x45, - 0x4b, 0x5f, 0x42, 0x4f, 0x54, 0x48, 0x10, 0x03, 0x12, 0x0b, 0x0a, 0x07, 0x43, 0x55, 0x52, 0x52, - 0x45, 0x4e, 0x54, 0x10, 0x04, 0x12, 0x08, 0x0a, 0x04, 0x4c, 0x41, 0x53, 0x54, 0x10, 0x06, 0x12, - 0x0c, 0x0a, 0x08, 0x4c, 0x41, 0x53, 0x54, 0x5f, 0x44, 0x55, 0x50, 0x10, 0x07, 0x12, 0x08, 0x0a, - 0x04, 0x4e, 0x45, 0x58, 0x54, 0x10, 0x08, 0x12, 0x0c, 0x0a, 0x08, 0x4e, 0x45, 0x58, 0x54, 0x5f, - 0x44, 0x55, 0x50, 0x10, 0x09, 0x12, 0x0f, 0x0a, 0x0b, 0x4e, 0x45, 0x58, 0x54, 0x5f, 0x4e, 0x4f, - 0x5f, 0x44, 0x55, 0x50, 0x10, 0x0b, 0x12, 0x08, 0x0a, 0x04, 0x50, 0x52, 0x45, 0x56, 0x10, 0x0c, - 0x12, 0x0c, 0x0a, 0x08, 0x50, 0x52, 0x45, 0x56, 0x5f, 0x44, 0x55, 0x50, 0x10, 0x0d, 0x12, 0x0f, - 0x0a, 0x0b, 0x50, 0x52, 0x45, 0x56, 0x5f, 0x4e, 0x4f, 0x5f, 0x44, 0x55, 0x50, 0x10, 0x0e, 0x12, - 0x0e, 0x0a, 0x0a, 0x53, 0x45, 0x45, 0x4b, 0x5f, 0x45, 0x58, 0x41, 0x43, 0x54, 0x10, 0x0f, 0x12, - 0x13, 0x0a, 0x0f, 0x53, 0x45, 0x45, 0x4b, 0x5f, 0x42, 0x4f, 0x54, 0x48, 0x5f, 0x45, 0x58, 0x41, - 0x43, 0x54, 0x10, 0x10, 0x12, 0x08, 0x0a, 0x04, 0x4f, 0x50, 0x45, 0x4e, 0x10, 0x1e, 0x12, 0x09, - 0x0a, 0x05, 0x43, 0x4c, 0x4f, 0x53, 0x45, 0x10, 0x1f, 0x2a, 0x48, 0x0a, 0x06, 0x41, 0x63, 0x74, - 0x69, 0x6f, 0x6e, 0x12, 0x0b, 0x0a, 0x07, 0x53, 0x54, 0x4f, 0x52, 0x41, 0x47, 0x45, 0x10, 0x00, - 0x12, 0x0a, 0x0a, 0x06, 0x55, 0x50, 0x53, 0x45, 0x52, 0x54, 0x10, 0x01, 0x12, 0x08, 0x0a, 0x04, - 0x43, 0x4f, 0x44, 0x45, 0x10, 0x02, 0x12, 0x0f, 0x0a, 0x0b, 0x55, 0x50, 0x53, 0x45, 0x52, 0x54, - 0x5f, 0x43, 0x4f, 0x44, 0x45, 0x10, 0x03, 0x12, 0x0a, 0x0a, 0x06, 0x44, 0x45, 0x4c, 0x45, 0x54, - 0x45, 0x10, 0x04, 0x2a, 0x24, 0x0a, 0x09, 0x44, 0x69, 0x72, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, - 0x12, 0x0b, 0x0a, 0x07, 0x46, 0x4f, 0x52, 0x57, 0x41, 0x52, 0x44, 0x10, 0x00, 0x12, 0x0a, 0x0a, - 0x06, 0x55, 0x4e, 0x57, 0x49, 0x4e, 0x44, 0x10, 0x01, 0x32, 0xa7, 0x01, 0x0a, 0x02, 0x4b, 0x56, - 0x12, 0x36, 0x0a, 0x07, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x16, 0x2e, 0x67, 0x6f, - 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, - 0x70, 0x74, 0x79, 0x1a, 0x13, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x56, 0x65, 0x72, 0x73, - 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x26, 0x0a, 0x02, 0x54, 0x78, 0x12, 0x0e, - 0x2e, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x2e, 0x43, 0x75, 0x72, 0x73, 0x6f, 0x72, 0x1a, 0x0c, - 0x2e, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x2e, 0x50, 0x61, 0x69, 0x72, 0x28, 0x01, 0x30, 0x01, - 0x12, 0x41, 0x0a, 0x0c, 0x53, 0x74, 0x61, 0x74, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x73, - 0x12, 0x1a, 0x2e, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x65, 0x43, - 0x68, 0x61, 0x6e, 0x67, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x13, 0x2e, 0x72, + 0x73, 0x18, 0x05, 0x20, 0x03, 0x28, 0x0c, 0x52, 0x03, 0x74, 0x78, 0x73, 0x12, 0x28, 0x0a, 0x0f, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x42, 0x61, 0x73, 0x65, 0x46, 0x65, 0x65, 0x18, + 0x06, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x42, + 0x61, 0x73, 0x65, 0x46, 0x65, 0x65, 0x22, 0x62, 0x0a, 0x12, 0x53, 0x74, 0x61, 0x74, 0x65, 0x43, + 0x68, 0x61, 0x6e, 0x67, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x20, 0x0a, 0x0b, + 0x77, 0x69, 0x74, 0x68, 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x08, 0x52, 0x0b, 0x77, 0x69, 0x74, 0x68, 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x12, 0x2a, + 0x0a, 0x10, 0x77, 0x69, 0x74, 0x68, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, + 0x6e, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x10, 0x77, 0x69, 0x74, 0x68, 0x54, 0x72, + 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2a, 0xe8, 0x01, 0x0a, 0x02, 0x4f, + 0x70, 0x12, 0x09, 0x0a, 0x05, 0x46, 0x49, 0x52, 0x53, 0x54, 0x10, 0x00, 0x12, 0x0d, 0x0a, 0x09, + 0x46, 0x49, 0x52, 0x53, 0x54, 0x5f, 0x44, 0x55, 0x50, 0x10, 0x01, 0x12, 0x08, 0x0a, 0x04, 0x53, + 0x45, 0x45, 0x4b, 0x10, 0x02, 0x12, 0x0d, 0x0a, 0x09, 0x53, 0x45, 0x45, 0x4b, 0x5f, 0x42, 0x4f, + 0x54, 0x48, 0x10, 0x03, 0x12, 0x0b, 0x0a, 0x07, 0x43, 0x55, 0x52, 0x52, 0x45, 0x4e, 0x54, 0x10, + 0x04, 0x12, 0x08, 0x0a, 0x04, 0x4c, 0x41, 0x53, 0x54, 0x10, 0x06, 0x12, 0x0c, 0x0a, 0x08, 0x4c, + 0x41, 0x53, 0x54, 0x5f, 0x44, 0x55, 0x50, 0x10, 0x07, 0x12, 0x08, 0x0a, 0x04, 0x4e, 0x45, 0x58, + 0x54, 0x10, 0x08, 0x12, 0x0c, 0x0a, 0x08, 0x4e, 0x45, 0x58, 0x54, 0x5f, 0x44, 0x55, 0x50, 0x10, + 0x09, 0x12, 0x0f, 0x0a, 0x0b, 0x4e, 0x45, 0x58, 0x54, 0x5f, 0x4e, 0x4f, 0x5f, 0x44, 0x55, 0x50, + 0x10, 0x0b, 0x12, 0x08, 0x0a, 0x04, 0x50, 0x52, 0x45, 0x56, 0x10, 0x0c, 0x12, 0x0c, 0x0a, 0x08, + 0x50, 0x52, 0x45, 0x56, 0x5f, 0x44, 0x55, 0x50, 0x10, 0x0d, 0x12, 0x0f, 0x0a, 0x0b, 0x50, 0x52, + 0x45, 0x56, 0x5f, 0x4e, 0x4f, 0x5f, 0x44, 0x55, 0x50, 0x10, 0x0e, 0x12, 0x0e, 0x0a, 0x0a, 0x53, + 0x45, 0x45, 0x4b, 0x5f, 0x45, 0x58, 0x41, 0x43, 0x54, 0x10, 0x0f, 0x12, 0x13, 0x0a, 0x0f, 0x53, + 0x45, 0x45, 0x4b, 0x5f, 0x42, 0x4f, 0x54, 0x48, 0x5f, 0x45, 0x58, 0x41, 0x43, 0x54, 0x10, 0x10, + 0x12, 0x08, 0x0a, 0x04, 0x4f, 0x50, 0x45, 0x4e, 0x10, 0x1e, 0x12, 0x09, 0x0a, 0x05, 0x43, 0x4c, + 0x4f, 0x53, 0x45, 0x10, 0x1f, 0x2a, 0x48, 0x0a, 0x06, 0x41, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, + 0x0b, 0x0a, 0x07, 0x53, 0x54, 0x4f, 0x52, 0x41, 0x47, 0x45, 0x10, 0x00, 0x12, 0x0a, 0x0a, 0x06, + 0x55, 0x50, 0x53, 0x45, 0x52, 0x54, 0x10, 0x01, 0x12, 0x08, 0x0a, 0x04, 0x43, 0x4f, 0x44, 0x45, + 0x10, 0x02, 0x12, 0x0f, 0x0a, 0x0b, 0x55, 0x50, 0x53, 0x45, 0x52, 0x54, 0x5f, 0x43, 0x4f, 0x44, + 0x45, 0x10, 0x03, 0x12, 0x0a, 0x0a, 0x06, 0x44, 0x45, 0x4c, 0x45, 0x54, 0x45, 0x10, 0x04, 0x2a, + 0x24, 0x0a, 0x09, 0x44, 0x69, 0x72, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x0b, 0x0a, 0x07, + 0x46, 0x4f, 0x52, 0x57, 0x41, 0x52, 0x44, 0x10, 0x00, 0x12, 0x0a, 0x0a, 0x06, 0x55, 0x4e, 0x57, + 0x49, 0x4e, 0x44, 0x10, 0x01, 0x32, 0xa7, 0x01, 0x0a, 0x02, 0x4b, 0x56, 0x12, 0x36, 0x0a, 0x07, + 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, + 0x13, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x52, + 0x65, 0x70, 0x6c, 0x79, 0x12, 0x26, 0x0a, 0x02, 0x54, 0x78, 0x12, 0x0e, 0x2e, 0x72, 0x65, 0x6d, + 0x6f, 0x74, 0x65, 0x2e, 0x43, 0x75, 0x72, 0x73, 0x6f, 0x72, 0x1a, 0x0c, 0x2e, 0x72, 0x65, 0x6d, + 0x6f, 0x74, 0x65, 0x2e, 0x50, 0x61, 0x69, 0x72, 0x28, 0x01, 0x30, 0x01, 0x12, 0x41, 0x0a, 0x0c, + 0x53, 0x74, 0x61, 0x74, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x73, 0x12, 0x1a, 0x2e, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x67, - 0x65, 0x30, 0x01, 0x42, 0x11, 0x5a, 0x0f, 0x2e, 0x2f, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x3b, - 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x13, 0x2e, 0x72, 0x65, 0x6d, 0x6f, 0x74, + 0x65, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x65, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x30, 0x01, 0x42, + 0x11, 0x5a, 0x0f, 0x2e, 0x2f, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x3b, 0x72, 0x65, 0x6d, 0x6f, + 0x74, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/interfaces/remote/kv.proto b/interfaces/remote/kv.proto index f79860b55..d72a14735 100644 --- a/interfaces/remote/kv.proto +++ b/interfaces/remote/kv.proto @@ -86,8 +86,7 @@ message StateChange { types.H256 blockHash = 3; repeated AccountChange changes = 4; repeated bytes txs = 5; // enable by withTransactions=true - uint64 blockBaseFee = 6; // enable by withTransactions=true - uint64 protocolBaseFee = 7; // enable by withTransactions=true + uint64 protocolBaseFee = 6; // enable by withTransactions=true } message StateChangeRequest { diff --git a/txpool/fetch.go b/txpool/fetch.go index 0392eb36e..24c0d9535 100644 --- a/txpool/fetch.go +++ b/txpool/fetch.go @@ -176,7 +176,7 @@ func (f *Fetch) receiveMessage(ctx context.Context, sentryClient sentry.SentryCl return nil } if err = f.handleInboundMessage(streamCtx, req, sentryClient); err != nil { - log.Warn("Handling incoming message: %s", "err", err) + log.Warn("Handling incoming message", "err", err) } if f.wg != nil { f.wg.Done() @@ -266,6 +266,10 @@ func (f *Fetch) handleInboundMessage(ctx context.Context, req *sentry.InboundMes return err } case sentry.MessageId_POOLED_TRANSACTIONS_65, sentry.MessageId_POOLED_TRANSACTIONS_66: + if !f.pool.Started() { + return nil + } + parseCtx := NewTxParseContext() txs := TxSlots{} if req.Id == sentry.MessageId_GET_POOLED_TRANSACTIONS_66 { @@ -277,6 +281,9 @@ func (f *Fetch) handleInboundMessage(ctx context.Context, req *sentry.InboundMes return err } } + if len(txs.txs) == 0 { + return nil + } if err := f.coreDB.View(ctx, func(tx kv.Tx) error { return f.pool.Add(tx, txs) }); err != nil { @@ -412,7 +419,7 @@ func (f *Fetch) handleStateChanges(ctx context.Context, client remote.KVClient) } if err := f.coreDB.View(ctx, func(tx kv.Tx) error { - return f.pool.OnNewBlock(tx, diff, unwindTxs, minedTxs, req.ProtocolBaseFee, req.BlockBaseFee, req.BlockHeight) + return f.pool.OnNewBlock(tx, diff, unwindTxs, minedTxs, req.ProtocolBaseFee, 0, req.BlockHeight) }); err != nil { log.Warn("onNewBlock", "err", err) } diff --git a/txpool/mocks_test.go b/txpool/mocks_test.go index f683e4c7a..e0ac9dce3 100644 --- a/txpool/mocks_test.go +++ b/txpool/mocks_test.go @@ -30,9 +30,12 @@ var _ Pool = &PoolMock{} // IdHashKnownFunc: func(hash []byte) bool { // panic("mock out the IdHashKnown method") // }, -// OnNewBlockFunc: func(db kv.Tx, stateChanges map[string]senderInfo, unwindTxs TxSlots, minedTxs TxSlots, protocolBaseFee uint64, blockBaseFee uint64, blockHeight uint64) error { +// OnNewBlockFunc: func(db kv.Tx, stateChanges map[string]senderInfo, unwindTxs TxSlots, minedTxs TxSlots, protocolBaseFee uint64, pendingBaseFee uint64, blockHeight uint64) error { // panic("mock out the OnNewBlock method") // }, +// StartedFunc: func() bool { +// panic("mock out the Started method") +// }, // } // // // use mockedPool in code that requires Pool @@ -53,7 +56,10 @@ type PoolMock struct { IdHashKnownFunc func(hash []byte) bool // OnNewBlockFunc mocks the OnNewBlock method. - OnNewBlockFunc func(db kv.Tx, stateChanges map[string]senderInfo, unwindTxs TxSlots, minedTxs TxSlots, protocolBaseFee uint64, blockBaseFee uint64, blockHeight uint64) error + OnNewBlockFunc func(db kv.Tx, stateChanges map[string]senderInfo, unwindTxs TxSlots, minedTxs TxSlots, protocolBaseFee uint64, pendingBaseFee uint64, blockHeight uint64) error + + // StartedFunc mocks the Started method. + StartedFunc func() bool // calls tracks calls to the methods. calls struct { @@ -91,17 +97,21 @@ type PoolMock struct { MinedTxs TxSlots // ProtocolBaseFee is the protocolBaseFee argument value. ProtocolBaseFee uint64 - // BlockBaseFee is the blockBaseFee argument value. - BlockBaseFee uint64 + // PendingBaseFee is the pendingBaseFee argument value. + PendingBaseFee uint64 // BlockHeight is the blockHeight argument value. BlockHeight uint64 } + // Started holds details about calls to the Started method. + Started []struct { + } } lockAdd sync.RWMutex lockAddNewGoodPeer sync.RWMutex lockGetRlp sync.RWMutex lockIdHashKnown sync.RWMutex lockOnNewBlock sync.RWMutex + lockStarted sync.RWMutex } // Add calls AddFunc. @@ -242,14 +252,14 @@ func (mock *PoolMock) IdHashKnownCalls() []struct { } // OnNewBlock calls OnNewBlockFunc. -func (mock *PoolMock) OnNewBlock(db kv.Tx, stateChanges map[string]senderInfo, unwindTxs TxSlots, minedTxs TxSlots, protocolBaseFee uint64, blockBaseFee uint64, blockHeight uint64) error { +func (mock *PoolMock) OnNewBlock(db kv.Tx, stateChanges map[string]senderInfo, unwindTxs TxSlots, minedTxs TxSlots, protocolBaseFee uint64, pendingBaseFee uint64, blockHeight uint64) error { callInfo := struct { Db kv.Tx StateChanges map[string]senderInfo UnwindTxs TxSlots MinedTxs TxSlots ProtocolBaseFee uint64 - BlockBaseFee uint64 + PendingBaseFee uint64 BlockHeight uint64 }{ Db: db, @@ -257,7 +267,7 @@ func (mock *PoolMock) OnNewBlock(db kv.Tx, stateChanges map[string]senderInfo, u UnwindTxs: unwindTxs, MinedTxs: minedTxs, ProtocolBaseFee: protocolBaseFee, - BlockBaseFee: blockBaseFee, + PendingBaseFee: pendingBaseFee, BlockHeight: blockHeight, } mock.lockOnNewBlock.Lock() @@ -269,7 +279,7 @@ func (mock *PoolMock) OnNewBlock(db kv.Tx, stateChanges map[string]senderInfo, u ) return errOut } - return mock.OnNewBlockFunc(db, stateChanges, unwindTxs, minedTxs, protocolBaseFee, blockBaseFee, blockHeight) + return mock.OnNewBlockFunc(db, stateChanges, unwindTxs, minedTxs, protocolBaseFee, pendingBaseFee, blockHeight) } // OnNewBlockCalls gets all the calls that were made to OnNewBlock. @@ -281,7 +291,7 @@ func (mock *PoolMock) OnNewBlockCalls() []struct { UnwindTxs TxSlots MinedTxs TxSlots ProtocolBaseFee uint64 - BlockBaseFee uint64 + PendingBaseFee uint64 BlockHeight uint64 } { var calls []struct { @@ -290,7 +300,7 @@ func (mock *PoolMock) OnNewBlockCalls() []struct { UnwindTxs TxSlots MinedTxs TxSlots ProtocolBaseFee uint64 - BlockBaseFee uint64 + PendingBaseFee uint64 BlockHeight uint64 } mock.lockOnNewBlock.RLock() @@ -298,3 +308,32 @@ func (mock *PoolMock) OnNewBlockCalls() []struct { mock.lockOnNewBlock.RUnlock() return calls } + +// Started calls StartedFunc. +func (mock *PoolMock) Started() bool { + callInfo := struct { + }{} + mock.lockStarted.Lock() + mock.calls.Started = append(mock.calls.Started, callInfo) + mock.lockStarted.Unlock() + if mock.StartedFunc == nil { + var ( + bOut bool + ) + return bOut + } + return mock.StartedFunc() +} + +// StartedCalls gets all the calls that were made to Started. +// Check the length with: +// len(mockedPool.StartedCalls()) +func (mock *PoolMock) StartedCalls() []struct { +} { + var calls []struct { + } + mock.lockStarted.RLock() + calls = mock.calls.Started + mock.lockStarted.RUnlock() + return calls +} diff --git a/txpool/pool.go b/txpool/pool.go index 8270d18dd..c2a27b107 100644 --- a/txpool/pool.go +++ b/txpool/pool.go @@ -39,9 +39,10 @@ import ( type Pool interface { // IdHashKnown check whether transaction with given Id hash is known to the pool IdHashKnown(hash []byte) bool + Started() bool GetRlp(hash []byte) []byte Add(db kv.Tx, newTxs TxSlots) error - OnNewBlock(db kv.Tx, stateChanges map[string]senderInfo, unwindTxs, minedTxs TxSlots, protocolBaseFee, blockBaseFee, blockHeight uint64) error + OnNewBlock(db kv.Tx, stateChanges map[string]senderInfo, unwindTxs, minedTxs TxSlots, protocolBaseFee, pendingBaseFee, blockHeight uint64) error AddNewGoodPeer(peerID PeerID) } @@ -120,7 +121,7 @@ type TxPool struct { blockHeight atomic.Uint64 protocolBaseFee atomic.Uint64 - blockBaseFee atomic.Uint64 + pendingBaseFee atomic.Uint64 senderID uint64 senderIDs map[string]uint64 @@ -224,22 +225,31 @@ func (p *TxPool) IdHashIsLocal(hash []byte) bool { } func (p *TxPool) AddNewGoodPeer(peerID PeerID) { p.recentlyConnectedPeers.AddPeer(peerID) } +func (p *TxPool) Started() bool { + p.lock.Lock() + defer p.lock.Unlock() + + protocolBaseFee := p.protocolBaseFee.Load() + return protocolBaseFee == 0 +} + func (p *TxPool) Add(coreDB kv.Tx, newTxs TxSlots) error { + log.Debug("[txpool.add]", "txs", len(newTxs.txs)) p.lock.Lock() defer p.lock.Unlock() if err := newTxs.Valid(); err != nil { return err } - protocolBaseFee, blockBaseFee := p.protocolBaseFee.Load(), p.blockBaseFee.Load() - if protocolBaseFee == 0 || blockBaseFee == 0 { + protocolBaseFee, pendingBaseFee := p.protocolBaseFee.Load(), p.pendingBaseFee.Load() + if protocolBaseFee == 0 || pendingBaseFee == 0 { return fmt.Errorf("non-zero base fee") } if err := setTxSenderID(coreDB, &p.senderID, p.senderIDs, p.senderInfo, newTxs); err != nil { return err } - if err := onNewTxs(p.senderInfo, newTxs, protocolBaseFee, blockBaseFee, p.pending, p.baseFee, p.queued, p.byHash, p.localsHistory); err != nil { + if err := onNewTxs(p.senderInfo, newTxs, protocolBaseFee, pendingBaseFee, p.pending, p.baseFee, p.queued, p.byHash, p.localsHistory); err != nil { return err } @@ -260,7 +270,7 @@ func (p *TxPool) Add(coreDB kv.Tx, newTxs TxSlots) error { return nil } -func onNewTxs(senderInfo map[uint64]*senderInfo, newTxs TxSlots, protocolBaseFee, blockBaseFee uint64, pending, baseFee, queued *SubPool, byHash map[string]*metaTx, localsHistory *simplelru.LRU) error { +func onNewTxs(senderInfo map[uint64]*senderInfo, newTxs TxSlots, protocolBaseFee, pendingBaseFee uint64, pending, baseFee, queued *SubPool, byHash map[string]*metaTx, localsHistory *simplelru.LRU) error { for i := range newTxs.txs { if newTxs.txs[i].senderID == 0 { return fmt.Errorf("senderID can't be zero") @@ -292,7 +302,7 @@ func onNewTxs(senderInfo map[uint64]*senderInfo, newTxs TxSlots, protocolBaseFee for i := range senderInfo { // TODO: aggregate changed senders before call this func - onSenderChange(senderInfo[i], protocolBaseFee, blockBaseFee) + onSenderChange(senderInfo[i], protocolBaseFee, pendingBaseFee) } pending.EnforceInvariants() @@ -310,7 +320,21 @@ func onNewTxs(senderInfo map[uint64]*senderInfo, newTxs TxSlots, protocolBaseFee return nil } -func (p *TxPool) OnNewBlock(coreDB kv.Tx, stateChanges map[string]senderInfo, unwindTxs, minedTxs TxSlots, protocolBaseFee, blockBaseFee, blockHeight uint64) error { + +func (p *TxPool) setBaseFee(protocolBaseFee, pendingBaseFee uint64) (uint64, uint64) { + p.protocolBaseFee.Store(protocolBaseFee) + hasNewVal := pendingBaseFee > 0 + if pendingBaseFee < protocolBaseFee { + pendingBaseFee = protocolBaseFee + } + if hasNewVal { + p.protocolBaseFee.Store(pendingBaseFee) + } + return protocolBaseFee, p.pendingBaseFee.Load() +} + +func (p *TxPool) OnNewBlock(coreDB kv.Tx, stateChanges map[string]senderInfo, unwindTxs, minedTxs TxSlots, protocolBaseFee, pendingBaseFee, blockHeight uint64) error { + log.Debug("[txpool.onNewBlock]", "unwinded", len(unwindTxs.txs), "mined", len(minedTxs.txs), "protocolBaseFee", protocolBaseFee, "blockHeight", blockHeight) p.lock.Lock() defer p.lock.Unlock() if err := unwindTxs.Valid(); err != nil { @@ -321,8 +345,7 @@ func (p *TxPool) OnNewBlock(coreDB kv.Tx, stateChanges map[string]senderInfo, un } p.blockHeight.Store(blockHeight) - p.protocolBaseFee.Store(protocolBaseFee) - p.blockBaseFee.Store(blockBaseFee) + protocolBaseFee, pendingBaseFee = p.setBaseFee(protocolBaseFee, pendingBaseFee) if err := setTxSenderID(coreDB, &p.senderID, p.senderIDs, p.senderInfo, unwindTxs); err != nil { return err @@ -336,7 +359,9 @@ func (p *TxPool) OnNewBlock(coreDB kv.Tx, stateChanges map[string]senderInfo, un } } - if err := onNewBlock(p.senderInfo, unwindTxs, minedTxs.txs, protocolBaseFee, blockBaseFee, p.pending, p.baseFee, p.queued, p.byHash, p.localsHistory); err != nil { + log.Debug("[txpool.onNewBlock]", "senderInfo", len(p.senderInfo)) + + if err := onNewBlock(p.senderInfo, unwindTxs, minedTxs.txs, protocolBaseFee, pendingBaseFee, p.pending, p.baseFee, p.queued, p.byHash, p.localsHistory); err != nil { return err } @@ -406,7 +431,7 @@ func setTxSenderID(coreDB kv.Tx, senderIDSequence *uint64, senderIDs map[string] return nil } -func onNewBlock(senderInfo map[uint64]*senderInfo, unwindTxs TxSlots, minedTxs []*TxSlot, protocolBaseFee, blockBaseFee uint64, pending, baseFee, queued *SubPool, byHash map[string]*metaTx, localsHistory *simplelru.LRU) error { +func onNewBlock(senderInfo map[uint64]*senderInfo, unwindTxs TxSlots, minedTxs []*TxSlot, protocolBaseFee, pendingBaseFee uint64, pending, baseFee, queued *SubPool, byHash map[string]*metaTx, localsHistory *simplelru.LRU) error { for i := range unwindTxs.txs { if unwindTxs.txs[i].senderID == 0 { return fmt.Errorf("onNewBlock.unwindTxs: senderID can't be zero") @@ -462,7 +487,7 @@ func onNewBlock(senderInfo map[uint64]*senderInfo, unwindTxs TxSlots, minedTxs [ for i := range senderInfo { // TODO: aggregate changed senders before call this func - onSenderChange(senderInfo[i], protocolBaseFee, blockBaseFee) + onSenderChange(senderInfo[i], protocolBaseFee, pendingBaseFee) } pending.EnforceInvariants() @@ -545,7 +570,7 @@ func unsafeAddToPool(senderInfo map[uint64]*senderInfo, unwindTxs TxSlots, to *S } } -func onSenderChange(sender *senderInfo, protocolBaseFee, blockBaseFee uint64) { +func onSenderChange(sender *senderInfo, protocolBaseFee, pendingBaseFee uint64) { prevNonce := sender.nonce cumulativeRequiredBalance := uint256.NewInt(0) minFeeCap := uint64(math.MaxUint64) @@ -559,10 +584,10 @@ func onSenderChange(sender *senderInfo, protocolBaseFee, blockBaseFee uint64) { needBalance.Add(needBalance, &it.metaTx.Tx.value) minFeeCap = min(minFeeCap, it.metaTx.Tx.feeCap) minTip = min(minTip, it.metaTx.Tx.tip) - if blockBaseFee >= minFeeCap { + if pendingBaseFee >= minFeeCap { it.metaTx.effectiveTip = minTip } else { - it.metaTx.effectiveTip = minFeeCap - blockBaseFee + it.metaTx.effectiveTip = minFeeCap - pendingBaseFee } // 1. Minimum fee requirement. Set to 1 if feeCap of the transaction is no less than in-protocol // parameter of minimal base fee. Set to 0 if feeCap is less than minimum base fee, which means @@ -598,7 +623,8 @@ func onSenderChange(sender *senderInfo, protocolBaseFee, blockBaseFee uint64) { // 4. Dynamic fee requirement. Set to 1 if feeCap of the transaction is no less than // baseFee of the currently pending block. Set to 0 otherwise. it.metaTx.subPool &^= EnoughFeeCapBlock - if it.metaTx.Tx.feeCap >= blockBaseFee { + if it.metaTx.Tx.feeCap >= pendingBaseFee { + fmt.Printf("setttttt: %d,%d,%d\n", protocolBaseFee, pendingBaseFee, it.metaTx.Tx.feeCap) it.metaTx.subPool |= EnoughFeeCapBlock } diff --git a/txpool/pool_fuzz_test.go b/txpool/pool_fuzz_test.go index 3c4e6098a..ee74189ea 100644 --- a/txpool/pool_fuzz_test.go +++ b/txpool/pool_fuzz_test.go @@ -236,12 +236,13 @@ func FuzzOnNewBlocks11(f *testing.F) { f.Add(u64[:], u64[:], u64[:], u64[:], sender[:], 1, 2) f.Add(u64[:], u64[:], u64[:], u64[:], sender[:], 3, 4) f.Add(u64[:], u64[:], u64[:], u64[:], sender[:], 10, 12) - f.Fuzz(func(t *testing.T, txNonce, values, tips, feeCap, sender []byte, protocolBaseFee1, blockBaseFee1 uint8) { + f.Fuzz(func(t *testing.T, txNonce, values, tips, feeCap, sender []byte, protocolBaseFee1, pendingBaseFee1 uint8) { t.Parallel() - protocolBaseFee, blockBaseFee := uint64(protocolBaseFee1%16+1), uint64(blockBaseFee1%16+1) - if protocolBaseFee == 0 || blockBaseFee == 0 { + protocolBaseFee, pendingBaseFee := uint64(protocolBaseFee1%16+1), uint64(pendingBaseFee1%8+1) + if protocolBaseFee == 0 || pendingBaseFee == 0 { t.Skip() } + pendingBaseFee += protocolBaseFee if len(sender) < 1+1+1 { t.Skip() } @@ -287,7 +288,7 @@ func FuzzOnNewBlocks11(f *testing.F) { assert.LessOrEqual(protocolBaseFee, tx.Tx.feeCap, msg) } if tx.subPool&EnoughFeeCapBlock > 0 { - assert.LessOrEqual(blockBaseFee, tx.Tx.feeCap, msg) + assert.LessOrEqual(pendingBaseFee, tx.Tx.feeCap, msg) } // side data structures must have all txs @@ -326,7 +327,7 @@ func FuzzOnNewBlocks11(f *testing.F) { assert.LessOrEqual(protocolBaseFee, tx.Tx.feeCap, msg) } if tx.subPool&EnoughFeeCapBlock > 0 { - assert.LessOrEqual(blockBaseFee, tx.Tx.feeCap, msg) + assert.LessOrEqual(pendingBaseFee, tx.Tx.feeCap, msg) } assert.True(senders[i.senderID].txNonce2Tx.Has(&nonce2TxItem{tx}), msg) @@ -353,7 +354,7 @@ func FuzzOnNewBlocks11(f *testing.F) { assert.LessOrEqual(protocolBaseFee, tx.Tx.feeCap, msg) } if tx.subPool&EnoughFeeCapBlock > 0 { - assert.LessOrEqual(blockBaseFee, tx.Tx.feeCap, msg) + assert.LessOrEqual(pendingBaseFee, tx.Tx.feeCap, msg) } assert.True(senders[i.senderID].txNonce2Tx.Has(&nonce2TxItem{tx}), "%s, %d, %x", msg, tx.Tx.nonce, tx.Tx.idHash) @@ -427,13 +428,13 @@ func FuzzOnNewBlocks11(f *testing.F) { // go to first fork //fmt.Printf("ll1: %d,%d,%d\n", pool.pending.Len(), pool.baseFee.Len(), pool.queued.Len()) unwindTxs, minedTxs1, p2pReceived, minedTxs2 := splitDataset(txs) - err = pool.OnNewBlock(nil, map[string]senderInfo{}, unwindTxs, minedTxs1, protocolBaseFee, blockBaseFee, 1) + err = pool.OnNewBlock(nil, map[string]senderInfo{}, unwindTxs, minedTxs1, protocolBaseFee, pendingBaseFee, 1) assert.NoError(err) check(unwindTxs, minedTxs1, "fork1") checkNotify(unwindTxs, minedTxs1, "fork1") // unwind everything and switch to new fork (need unwind mined now) - err = pool.OnNewBlock(nil, map[string]senderInfo{}, minedTxs1, minedTxs2, protocolBaseFee, blockBaseFee, 2) + err = pool.OnNewBlock(nil, map[string]senderInfo{}, minedTxs1, minedTxs2, protocolBaseFee, pendingBaseFee, 2) assert.NoError(err) check(minedTxs1, minedTxs2, "fork2") checkNotify(minedTxs1, minedTxs2, "fork2")