Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mybee
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
mybee
Commits
d4aeb344
Unverified
Commit
d4aeb344
authored
Jun 20, 2021
by
metacertain
Committed by
GitHub
Jun 20, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: cache verifications (#2160)
parent
003bea49
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
7 deletions
+47
-7
node.go
pkg/node/node.go
+1
-1
sender_matcher.go
pkg/transaction/sender_matcher.go
+40
-1
sender_matcher_test.go
pkg/transaction/sender_matcher_test.go
+6
-5
No files found.
pkg/node/node.go
View file @
d4aeb344
...
...
@@ -332,7 +332,7 @@ func NewBee(addr string, publicKey *ecdsa.PublicKey, signer crypto.Signer, netwo
lightNodes
:=
lightnode
.
NewContainer
(
swarmAddress
)
senderMatcher
:=
transaction
.
NewMatcher
(
swapBackend
,
types
.
NewEIP155Signer
(
big
.
NewInt
(
chainID
)))
senderMatcher
:=
transaction
.
NewMatcher
(
swapBackend
,
types
.
NewEIP155Signer
(
big
.
NewInt
(
chainID
))
,
stateStore
)
p2ps
,
err
:=
libp2p
.
New
(
p2pCtx
,
signer
,
networkID
,
swarmAddress
,
addr
,
addressbook
,
stateStore
,
lightNodes
,
senderMatcher
,
logger
,
tracer
,
libp2p
.
Options
{
PrivateKey
:
libp2pPrivateKey
,
...
...
pkg/transaction/sender_matcher.go
View file @
d4aeb344
...
...
@@ -6,18 +6,29 @@ import (
"errors"
"fmt"
"math/big"
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethersphere/bee/pkg/crypto"
"github.com/ethersphere/bee/pkg/storage"
"github.com/ethersphere/bee/pkg/swarm"
)
type
Matcher
struct
{
backend
Backend
storage
storage
.
StateStorer
signer
types
.
Signer
}
const
(
overlayPrefix
=
"verified_overlay_"
)
func
peerOverlayKey
(
peer
swarm
.
Address
)
string
{
return
fmt
.
Sprintf
(
"%s%s"
,
overlayPrefix
,
peer
.
String
())
}
var
(
ErrTransactionNotFound
=
errors
.
New
(
"transaction not found"
)
ErrTransactionPending
=
errors
.
New
(
"transaction in pending status"
)
...
...
@@ -26,8 +37,15 @@ var (
ErrOverlayMismatch
=
errors
.
New
(
"overlay mismatch"
)
)
func
NewMatcher
(
backend
Backend
,
signer
types
.
Signer
)
*
Matcher
{
type
overlayVerification
struct
{
nextBlockHash
[]
byte
verified
bool
timeStamp
time
.
Time
}
func
NewMatcher
(
backend
Backend
,
signer
types
.
Signer
,
storage
storage
.
StateStorer
)
*
Matcher
{
return
&
Matcher
{
storage
:
storage
,
backend
:
backend
,
signer
:
signer
,
}
...
...
@@ -35,6 +53,17 @@ func NewMatcher(backend Backend, signer types.Signer) *Matcher {
func
(
m
*
Matcher
)
Matches
(
ctx
context
.
Context
,
tx
[]
byte
,
networkID
uint64
,
senderOverlay
swarm
.
Address
)
([]
byte
,
error
)
{
var
val
overlayVerification
err
:=
m
.
storage
.
Get
(
peerOverlayKey
(
senderOverlay
),
&
val
)
if
err
!=
nil
&&
!
errors
.
Is
(
err
,
storage
.
ErrNotFound
)
{
return
nil
,
err
}
else
if
val
.
verified
{
// add cache invalidation
return
val
.
nextBlockHash
,
nil
}
incomingTx
:=
common
.
BytesToHash
(
tx
)
nTx
,
isPending
,
err
:=
m
.
backend
.
TransactionByHash
(
ctx
,
incomingTx
)
...
...
@@ -75,5 +104,15 @@ func (m *Matcher) Matches(ctx context.Context, tx []byte, networkID uint64, send
return
nil
,
ErrOverlayMismatch
}
err
=
m
.
storage
.
Put
(
peerOverlayKey
(
senderOverlay
),
&
overlayVerification
{
timeStamp
:
time
.
Now
(),
verified
:
true
,
nextBlockHash
:
nextBlockHash
,
})
if
err
!=
nil
{
return
nil
,
err
}
return
nextBlockHash
,
nil
}
pkg/transaction/sender_matcher_test.go
View file @
d4aeb344
...
...
@@ -9,6 +9,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethersphere/bee/pkg/crypto"
statestore
"github.com/ethersphere/bee/pkg/statestore/mock"
"github.com/ethersphere/bee/pkg/swarm"
"github.com/ethersphere/bee/pkg/transaction"
"github.com/ethersphere/bee/pkg/transaction/backendmock"
...
...
@@ -30,7 +31,7 @@ func TestMatchesSender(t *testing.T) {
return
nil
,
false
,
errors
.
New
(
"transaction not found by hash"
)
})
matcher
:=
transaction
.
NewMatcher
(
backendmock
.
New
(
txByHash
),
nil
)
matcher
:=
transaction
.
NewMatcher
(
backendmock
.
New
(
txByHash
),
nil
,
statestore
.
NewStateStore
()
)
_
,
err
:=
matcher
.
Matches
(
context
.
Background
(),
trx
,
0
,
swarm
.
NewAddress
([]
byte
{}))
if
!
errors
.
Is
(
err
,
transaction
.
ErrTransactionNotFound
)
{
...
...
@@ -43,7 +44,7 @@ func TestMatchesSender(t *testing.T) {
return
nil
,
true
,
nil
})
matcher
:=
transaction
.
NewMatcher
(
backendmock
.
New
(
txByHash
),
nil
)
matcher
:=
transaction
.
NewMatcher
(
backendmock
.
New
(
txByHash
),
nil
,
statestore
.
NewStateStore
()
)
_
,
err
:=
matcher
.
Matches
(
context
.
Background
(),
trx
,
0
,
swarm
.
NewAddress
([]
byte
{}))
if
!
errors
.
Is
(
err
,
transaction
.
ErrTransactionPending
)
{
...
...
@@ -59,7 +60,7 @@ func TestMatchesSender(t *testing.T) {
signer
:=
&
mockSigner
{
err
:
errors
.
New
(
"can not sign"
),
}
matcher
:=
transaction
.
NewMatcher
(
backendmock
.
New
(
txByHash
),
signer
)
matcher
:=
transaction
.
NewMatcher
(
backendmock
.
New
(
txByHash
),
signer
,
statestore
.
NewStateStore
()
)
_
,
err
:=
matcher
.
Matches
(
context
.
Background
(),
trx
,
0
,
swarm
.
NewAddress
([]
byte
{}))
if
!
errors
.
Is
(
err
,
transaction
.
ErrTransactionSenderInvalid
)
{
...
...
@@ -93,7 +94,7 @@ func TestMatchesSender(t *testing.T) {
},
nil
})
matcher
:=
transaction
.
NewMatcher
(
backendmock
.
New
(
txByHash
,
trxReceipt
,
headerByNum
),
signer
)
matcher
:=
transaction
.
NewMatcher
(
backendmock
.
New
(
txByHash
,
trxReceipt
,
headerByNum
),
signer
,
statestore
.
NewStateStore
()
)
_
,
err
:=
matcher
.
Matches
(
context
.
Background
(),
trx
,
0
,
swarm
.
NewAddress
([]
byte
{}))
if
err
==
nil
{
...
...
@@ -127,7 +128,7 @@ func TestMatchesSender(t *testing.T) {
addr
:
common
.
HexToAddress
(
"0xff"
),
}
matcher
:=
transaction
.
NewMatcher
(
backendmock
.
New
(
trxReceipt
,
headerByNum
,
txByHash
),
signer
)
matcher
:=
transaction
.
NewMatcher
(
backendmock
.
New
(
trxReceipt
,
headerByNum
,
txByHash
),
signer
,
statestore
.
NewStateStore
()
)
senderOverlay
:=
crypto
.
NewOverlayFromEthereumAddress
(
signer
.
addr
.
Bytes
(),
0
,
nextBlockHeader
.
Hash
()
.
Bytes
())
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment