@@ -2,7 +2,9 @@ package builder
2
2
3
3
import (
4
4
"errors"
5
+ "math/big"
5
6
_ "os"
7
+ "sync"
6
8
"time"
7
9
8
10
"github.com/ethereum/go-ethereum/common/hexutil"
@@ -47,6 +49,10 @@ type Builder struct {
47
49
builderSecretKey * bls.SecretKey
48
50
builderPublicKey boostTypes.PublicKey
49
51
builderSigningDomain boostTypes.Domain
52
+
53
+ bestMu sync.Mutex
54
+ bestAttrs BuilderPayloadAttributes
55
+ bestBlockProfit * big.Int
50
56
}
51
57
52
58
func NewBuilder (sk * bls.SecretKey , bc IBeaconClient , relay IRelay , builderSigningDomain boostTypes.Domain , eth IEthereumService ) * Builder {
@@ -63,10 +69,25 @@ func NewBuilder(sk *bls.SecretKey, bc IBeaconClient, relay IRelay, builderSignin
63
69
builderPublicKey : pk ,
64
70
65
71
builderSigningDomain : builderSigningDomain ,
72
+ bestBlockProfit : big .NewInt (0 ),
66
73
}
67
74
}
68
75
69
- func (b * Builder ) onSealedBlock (executableData * beacon.ExecutableDataV1 , block * types.Block , proposerPubkey boostTypes.PublicKey , proposerFeeRecipient boostTypes.Address , slot uint64 ) error {
76
+ func (b * Builder ) onSealedBlock (executableData * beacon.ExecutableDataV1 , block * types.Block , proposerPubkey boostTypes.PublicKey , proposerFeeRecipient boostTypes.Address , attrs * BuilderPayloadAttributes ) error {
77
+ b .bestMu .Lock ()
78
+ defer b .bestMu .Unlock ()
79
+
80
+ // Do not submit blocks that don't improve the profit
81
+ if b .bestAttrs != * attrs {
82
+ b .bestAttrs = * attrs
83
+ b .bestBlockProfit .SetInt64 (0 )
84
+ } else {
85
+ if block .Profit .Cmp (b .bestBlockProfit ) <= 0 {
86
+ log .Info ("Ignoring block that is not improving the profit" )
87
+ return nil
88
+ }
89
+ }
90
+
70
91
payload , err := executableDataToExecutionPayload (executableData )
71
92
if err != nil {
72
93
log .Error ("could not format execution payload" , "err" , err )
@@ -81,7 +102,7 @@ func (b *Builder) onSealedBlock(executableData *beacon.ExecutableDataV1, block *
81
102
}
82
103
83
104
blockBidMsg := boostTypes.BidTrace {
84
- Slot : slot ,
105
+ Slot : attrs . Slot ,
85
106
ParentHash : payload .ParentHash ,
86
107
BlockHash : payload .BlockHash ,
87
108
BuilderPubkey : b .builderPublicKey ,
@@ -110,6 +131,8 @@ func (b *Builder) onSealedBlock(executableData *beacon.ExecutableDataV1, block *
110
131
return err
111
132
}
112
133
134
+ b .bestBlockProfit .Set (block .Profit )
135
+
113
136
return nil
114
137
}
115
138
@@ -150,7 +173,7 @@ func (b *Builder) OnPayloadAttribute(attrs *BuilderPayloadAttributes) error {
150
173
return errors .New ("did not receive the payload" )
151
174
}
152
175
153
- err := b .onSealedBlock (executableData , block , proposerPubkey , vd .FeeRecipient , attrs . Slot )
176
+ err := b .onSealedBlock (executableData , block , proposerPubkey , vd .FeeRecipient , attrs )
154
177
if err != nil {
155
178
log .Error ("could not run block hook" , "err" , err )
156
179
return err
0 commit comments