That is why we have rest rules. Pilots get paid a lot of money to be safe and competent when on duty. It is our responsibility to be alert throughout the flight.
I know it is hard to prepare for an all nighter rested because I couldn't when I had to do them. Sleeping on duty is not the solution.